Declare a Read-Only Variable with the const Keyword

Tell us what’s happening:

Your code so far


function printManyTimes(str) {
  "use strict";

  // change code below this line

  const sentence = str + " is cool!";
  for(let i = 0; i < str.length; i+=2) {
    console.log(str);
  }

  // change code above this line

}
printManyTimes("freeCodeCamp");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/declare-a-read-only-variable-with-the-const-keyword

Do you have a question?

i hade a problem in const sentence and didnt know what is it

The only that stands out to me is that you aren’t actually using your sentence anywhere in the code.

i have found the solution sentences must be in upper case

2 Likes

I also have the same problem…:confused:

const sentence = “…”
must be
const SENTENCE = “…”

2 Likes

thank you…:grinning:

sorry, did you pass this challenge? i’m getting the same error with it.

Here is my code:
function printManyTimes(str) {

// change code below this line

const SENTENCE = str + " is cool!";
for(let i = 0; i < str.length; i+=2) {
console.log(SENTENCE);
}
// change code above this line

}
printManyTimes(“freeCodeCamp”);

What error do you get? Could you send a screenshot?

1 Like

this is my problem :frowning:

Yeah, I got exactly the same. It seems there is an issue on this challenge. I took a look at the freeCodeCamp’s source code and the regex used to test that you used console.log(SENTENCE); seems to be incorrect. It explains why you get an unexpected token ?

So don’t worry, your solution is the right one :wink:

I suggest you move on another challenge waiting for the fix (I’m going to open a PR tonight) :slight_smile:

3 Likes

many thanks for your advice, i will move on other challenge and waiting for the fix :smiley:

Thanks. This was driving me nuts as it isn’t really a hard problem. Kept thinking I was misreading something in the challenge like - did they say to make the output .toUpperCase() or something? More frustrating because in the actual console everything seemed to do what it’s supposed to.

Well, some redemption. After looking into the FCC source it appears that this:

.match(/console.log/(/s*?SENTENCE/s*?/)/s*?;/g)

Should be something like this:

.match(/console\.log\(\s*?SENTENCE\s*?\)\s*?;/g)

Seems someone already came to the same conclusion and submitted this fix to Github - but at least now I can fully rest knowing this problem didn’t beat me completely.

1 Like

awww, and I just wanted to complete this one too.

so, is this bug already fixed?

Doesn’t seem like it

For these who were following this topic, the problem has been fixed, so you can now do this challenge :slightly_smiling_face: