I do not know where the statement comes from, but it is not good, I would rethink if it is worth continuing with this source of study. For example he talk about x
and have the loop variable be i
. Maybe he wants you to create a variable x
which is exactly the value of i
, but for what? Maybe you want me to use x
and not i
, but it makes no sense inside the writing. And in fact a statement should not give names to variables, part of learning should be learning to name well on its own.
Well, after editing we realized that the problem was not even the statement was in what was posted here (apparently my interpretation was correct), we need to be careful with what question, ask is much easier than programming, if you make a mistake in this complicates. The site is reporting errors that could not happen in the code posted here, so maybe what was posted here is different than what posted there, it gets more complicated still help, I tried.
Despite the ambiguity I will interpret that you must print from 0 to 3, inclusive. Your code is printing from 0 to 2 exclusive (the 2 neither prints). To go to 3 you must use this number and not 2 as it was used (this is not a matter of knowing how to program), and to be inclusive and not exclusive you must use the <=
(smaller or equal) and not the <
(minor) (this is mathematics and not programming).
There were no other mistakes, no programming mistakes. And it’s not making any mistakes in the code, it’s just not giving the expected result and the site you’re using to fix this is denying this result, you need to understand that the code is not wrong, the algorithm is not doing the intended, it’s a misguided logic, without understanding it will have difficulties (and will have others if you fail to understand that this site is not the normal execution process of a code.
If you still continue with the error is because the wrong statement means something else, for example you should use <
because 3 is exclusive.
Note that I improved some things in the code that do not give error or bad result, but it is good to keep learning.
The function flame may not be needed on the site you are using, which we don’t know what it is and so we can’t help any more than this. A thorough reading in Stack Overflow Survival Guide in English would help to ask better questions and prepare better for programming.
function passandoPor() {
for (var i = 0; i <= 3; i++) console.log("aqui eu tenho o valor de", i);
}
passandoPor();
I put in the Github for future reference.
You want to perform the function?
– Samuel Ives
Yeah! Making a mistake!
– SOM
What error are you getting? Click [Edit] to edit add your reply and add more details, such as the error you say is occurring.
– Luiz Felipe
All right, I edited!
– SOM
The problem is in the iteration condition of the
for
, your loop iterates whilei
is less than 2. You have to iterate whilei
is less than or equal to 3. Read Instruction for– Augusto Vasques
Ok! I’ll try! Thank you very much!
– SOM
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site
– Maniero