+ 1
Why is my code continue to show result after if
I want the code to give me the result of division by 3, only if id dose divided by it var div = 2852; var res=div/3; if (div%3==0) {alert ("your number can be divided by 3");} document.write("the result is " + res); else { alert("sry it can't"); }
2 Antworten
+ 1
After closing the if block, you write "the result is..." and then you open an else block. That can't work, because you can only open an else block directly after closing an if block. Just move the } after the alert to "the result is...".
+ 1
Thank you for the explanation! This was my first code, and i really enjoyed it.