Why is my code not running? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is my code not running?

I have started this code, and it looks like this: var age = 1; while(age < 7) age =+ 1; document.write(age) But the problem is, it won't show the var "age" when i run the code. It's probably just me missing something totally obvious but i cant figure it out. Anyone?

26th Aug 2016, 9:00 PM
Bravesboy54
7 Answers
+ 3
Write += instead of =+.
26th Aug 2016, 10:05 PM
Zen
Zen - avatar
+ 1
There isn't any error message because there isn't any error as far as the interpreter is concerned: your "age=+1;" is being interpreted as "age = +1;" (with the plus as an unary operator. In other words, you were just setting your variable to 1 over and over in your loop.
27th Aug 2016, 8:16 AM
Zen
Zen - avatar
+ 1
It doesn't display any error message because you haven't made it to. In JS you can use: Try { alert("Try runs some code and if an error is found the catch does something."); } then use catch { alert("Catch does something if an error is found."); } You can also use finally { alert("This code will always do something even if no error is found."); } Explanation: Try runs the code. Catch does something if an error is found. Finally always runs. For example: Try { aler("Note that the t in alert is missing."); } Catch { alert("Error!"); } Result: Error!. I have no idea why SoloLearn didn't include error handling in their courses.
27th Aug 2016, 7:00 PM
Oscar
Oscar - avatar
0
And it also doesnt display any error message
26th Aug 2016, 9:01 PM
Bravesboy54
0
the biggest problem is the format: while (age < 7){ age += 1; document.write (age); } JS does understand that age is in the while loop
11th Sep 2016, 3:24 AM
John Call
John Call - avatar
0
var age = 1; while(age < 7) age =age+ 1; document.write(age) agora esta corrigido mas tem que adicionar um vento pra funçao funcionar tipo assim: var age = 1; function clicked(){ if(age < 7) age =age+ 1; } document.write("<button onclick='clicked()'>click here</button>"+age)
29th Sep 2016, 12:00 PM
Claudio Santos
Claudio Santos - avatar
0
void bot(int mode,string name) { if(mode==1){ cout<<"Welcome,"<<name<<"!"; } else if(mode==2){ cout<<"Goodbye,"<<name<<"!"; } else{ cout<<"Try again"; } } Why this is not running it's all correct
3rd Jul 2023, 7:05 AM
kanchi soni
kanchi soni - avatar