1
I wanted to make a site where when I click on the image it doubles in size and width, but can do this only once, and if I do more, a warning appears preventing it. Similarly, if it is the default size, you cannot decrease it, and a warning will appear, but if you increase it and try to decrease it, this will be possible.
I stopped at the code around here:
function passar(img){
var d = 0;
if (d == 0){
var x = confirm("tem certeza que deseja aumentar a imagem?");
if(x == true && d ==0){
d=d+1;
img.height=img.height*2;
img.width=img.width*2;
}
else if (x== true && d==1)
window.alert("Não é possivel aumentar mais");
else{
var y = confirm("tem certeza que deseja diminuir a imagem?");
if ( y==true && d==1){
d=d-1;
img.height=img.height/2;
img.width=img.width/2;
}
else if(y == true && d==0)
window.alert("Não é possivel");
}}}
My biggest problem is being that when one if-else
locks the key, the d
does not possess the new value I gave it d=d+1
or d=d-1
, I’ve tried other ways but I can’t find a solution.
Try to use
d += 1
andd -= 1
– Rubens Barbosa
did not take, continued the same way, when it closes the key of the IF-ELSE the d(counter) loses the value, being limited to the own if and Else.
– henrique fernando