-3
EDIT: the problem after all was why was calling the function passoApasso()
, it was only necessary to write the function, the program itself called the function, so it appeared repeated the numbers.
The code below only serve if you want to print 01234
, without the \n
, I’ll let him down, but is not the answer to the question!
ANCIENT ANSWER
The problem is that you are printing with the console.log
normally, then she does the line break:
0
1
2
3
4
Instead of printing out 01234
as the exercise asks, to solve this just concatenate the numbers with a string:
function passoAPasso(){
let concat = "";
for (var i = 0; i < 5; i++){
concat = concat + (i + ""); // os números são convertido para string, porque você está somando ele com uma string, antes de concatenar
}
console.log(concat);
}
passoAPasso();
Explaining a little code: in the first iteration you have 1 + ""
, what generates "1"
, that is, now is a string and input you do concat + "1"
, Concat is an empty string, so the result is "1"
.
In the second iteration, you have 2 + ""
, what generates "2"
, and then makes concat + "2"
, what generates "12"
and so on.
i used your code and gave the following answer " Your solution did not pass the tests Test results: Print stepPasso() should print 01234 View details '01234 n01234 n' == '0 n1 N2 N3 N4 n'"
– William Felipe
Do a test, use your initial code, but don’t call the function
passoApasso()
, write somenta `Function, so it looks like it’s printing twice.– leofalmeida
MUITOOOO THANK YOU CARAAA WAS LONG TRYING TO SOLVE AND I AM HALF DUMB IN JS STILL. VALEUU MSM.
– William Felipe
It happens haha, stay firm!
– leofalmeida