7/13 help


#1

Java-S
not sure what i had done wrong but i damn done messed up
// Example of infinite loop. THIS WILL CRASH YOUR
// BROWSER. Don't run the code without changing it!

for (var i = 1; i >= 10; i++1) {
console.log(i);
}


#2

Browser crashing is a sign of an infinite loop. In your case this doesn't work as expected:

i++1

don't know what this specific thing does but it doesn't seem to increase by one. The only confusing this is that this code should not crash your browser but it should not even run as your condition is false:

i >= 10
with i =1 means
1 >= 10

Anyway the correct code to increase a number by one is i=i+i or its shortcuts i+=1 or ++i or i++


#3

thanks, this really helps me in my studies


#4

I am stuck
what is the correct code?
it is mine
for (var i = 10; i = 0; i--) {
console.log(i);
}


#5

Oh i did it.
It was easy
:smile:


#6

how did you do it without crashing the browser


#7

The code you used (referenced below) is the same that I did. How did you change it to make it work?

for (var i = 10; i = 0; i--) {
console.log(i);
}


#8

for (var i = 10; i == 0; i--) {
                    ^

#9

Thank you! (Excellent pikachu avatar, btw)


#10

how did you do it plz help


#11

hi sir how are you ?
i have need for your help please solve this lesson.

(12. Loops and arrays II)


#12

for (var i = 10; i = 0; i--)
{
console.log(10)
}
what am i doing wrong


#13

Just asking:

If you're going to just print 10, what's the use of doing a for loop? Also, if you want to do a for loop that prints the NUMBER, you need to change

To console.log(i). Why? Because it will print the way the number goes until it arrives at 0. Which shows our next problem.

You did your comparators incorrectly in here, specifically:

"=" means something like "turn into" in JavaScript.
"===" means equal to. In type AND value. So, you must change it into "==="

Note: "==" only looks at value, not type. (Just in case you ask) What I am saying is that this is what "==" does:

'1' == 1 //true

But "===" does:
'1' === 1 //false

Hope it helped!:smiley:


#14

for (var i = 10; i = 0; i--)

for loops are as follows

for (initialization ; condition ; incrementation/ decrementation "postfix") { ... }

so try changing your for loop to.

for (var i = 10; i > 0; i--) 
{
console.log(10);
}

@ragezapper I believe that doing the "==" would never allow the for loop to be true to increment or decrement. So it's best to have the condition replaced so that it can process as I have in the above code.


#15

A post was merged into an existing topic: Hi dear you help me in this problem


#16

Hello there, this is actually the right syntax!
Happy coding :wink:
for (var i = 10; i >= 0; i--)
{
console.log(i);
}


#17

for (var i = 10; i>-1; i--) {
console.log(i);
}