lundi 29 décembre 2014

Code will execute both if and else statements. Javascript [on hold]

I have an array called used.I have a function which add a code in the array but checks if the code has been added again.If it has been added it has to say "False" else True the problem is that it will say both false and true. Here is my code:



var used=[];//use that to check if the user has added the code to favourites again

var x='',y='',blur='',r="",g="",b="",op="",color="rgb(0,0,0)",shadow=''; //create the variables that will be used
function update(){
x=$("#x").val();
y=$("#y").val();
op=$("#o").val();
r=$("#red").val();
g=$("#green").val();
b=$("#blue").val();
blur=$("#blur").val();
shadow = x+"px "+y+"px ";


}
$(document).ready(function(){
$("#addC").click(function(){
if(used.indexOf(shadow) != -1){
alert("false");
}
else{
used.push(shadow);
alert("True");

}
});
$('.shadow-slider').change(function(){

update();

if (op != 1){
if(op.length > 3){op=op.substring(0, 3);}
color="rgba("+r+","+g+","+b+","+op+")";
}
else{
color="rgb("+r+","+g+","+b+")";
}
if (blur != 0){shadow += blur+"px ";}
shadow += color;
$('#object').css("text-shadow",shadow);
$('#code-output').html("text-shadow:"+shadow+";");

});



});


Shadow is a global variable which changes depending on some sliders of my page.Any ideas?


Aucun commentaire:

Enregistrer un commentaire