This forum is now read-only. Please use our new forums! Go to forums
iteration: what's that mean in coding language? I can't figure out how to make I++ equal to 2
in the section entitled “bring it up (and down)” and the directions read: “After the variable i is declared, call i++ twice to get i equal to 2. This should involve two separate lines with i++; on them. Try it out now.” and the hint reads: “Here you can have two separate lines of iteration. Each should contain just i++.”
What do they mean “call…” and “separate lines of iteration”?? I just don’t know what I’m trying to do.
I tried this:
var i = 0; console.log( “i is equal to “ + i ); var i++ = 2; var i++ = 2;
as well as just: var i = 0; console.log( “i is equal to “ i++ ); i++
I really am a total beginner with coding, and I’m lost. The lessons prior to these were the FIRST I’ve ever had with coding. I don’t really understand how to do this or what I’m trying to do… up until now, I think I’d understood the directions pretty well, but now I am lost :(
Thanks for any advice here.
Answer 4f45265441b1b1000300ceb7
The answer is to look at the order in which you’re doing things:
var i = 0; /* you set i to zero */
console.log( "i is equal to " + i ); /* then you print out the current value, which is still zero */
i++; /* then you increment i by 1 (add 1 to i) */
i++; /* and then you do it again */
So at the end of the script, the correct value of 2 is in the variable i
, you’ve just printed it before you’ve added to it. Can you see how you might fix that?
Answer 4f4013a7faaa8b0003023b3f
woops! of course, seconds after I post the question, I then figure it out. It’s the simplest thing in the world too! The correct code for this exercise is just:
var i = 0; console.log( “i is equal to “ + i ); i++; i++;
Answer 4f401555a5b1830003024503
only, actually, I take it back! codecacademy thinks I’m right, but the answer shown is actually 1 in this exercise as well as one in the decrementor exercise that follows. When the answers should be 2 and 0, respectively. So, although codecacaemdy indicates I should move on to the next exercise and gave me my points, something is not right!
any ideas?? the above code gets me “Ok-ed” by the academy, but does not give the values it said should get…
Answer 4f4376c48804d20003024a7d
Answer 4f499965df4f90000300b5c5
i++; means adding 1 to i or it equals to the statement i=i+1; it could say an iteration because it adding a value and return its result to itself.
on the scratch, we start with var i=0; by put statement i++; makes i equals to 1. an then we put i++; again so now i equals to 2. this is the objective.
that’s why we should put i++; twice to get i=2 at the end.
another similar statement:
i– equals to i=i-1 i+=n equals to i=i+n i-=n equals to i=i-n i*=n eqals to i=i*n i/=n equals to i=i/n i%=n equals to i=i%n
may it helps;
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency