Why is my code continue to show result after if | Sololearn: Learn to code for FREE!

+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/17/2018 9:57:42 AM

Emil Tayeb

2 Answers

New Answer

+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.