I am trying to console log the output of "55" for my ‘total’ variable in javascript by adding the number 1 through 10. What is wrong with my script? I have tried debugging. The result was nothing in the console output. Please ignore any syntax mistakes as I will fix those. I’m very new to programming and I heard that this community is helpful so hopefully I’m in the right place.
var total=0;
var count=1;
for (t=0; t<11; t++
total=count+total;
count=count+1
;
console.log (total);
3
Answers
It appears you’re missing the closing the parenthesis after the For condition, and the loop’s content isn’t enclosed in brackets.
I am also noticing that you’re starting off with the
t=0
which might not be what you’d expect (0..10, resulting in 11 loops).Try the these suggested changes and let me know if that fixes it for you.
you are missing syntax in loop
and let t=0 and t<10 times to get 55 (//loops 9 times)
I hope it helps!
This should work