Tell us what’s happening:
Hello. Could someone explain why we have declared ‘i’ as a variable but we aren’t using it anywhere in the code? How is it connected to the str + “is cool!”?
Also, could you explain that code as well "(let i = 0; i < str.length; i+=2) ". I’ve been through the lesson but some things aren’t very clear for me.
So, basically i = 0 means that the process starts from zero? i < str.length = i < 12 in this case? i+=2 means we are adding ‘2’ on each cycle, but why do we only have 6x " freecodecamp is cool!" sentences? (taken from the console in the challenge).
Thanks in advance. Expect such questions from me in the future!
Your code so far
function printManyTimes(str) {
// Only change code below this line
const sentence = str + " is cool!";
for (let i = 0; i < str.length; i+=2) {
console.log(sentence);
}
// Only change code above this line
}
printManyTimes("freeCodeCamp");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0
.
Challenge: Declare a Read-Only Variable with the const Keyword
Link to the challenge: