Declare a Read-Only Variable with the const Keyword

Declare a Read-Only Variable with the const Keyword
0

#1

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


Declare a Read-Only Variable with the const Keyword - unexpected character
#2

Do you have a question?


#3

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


#4

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


#5

i have found the solution sentences must be in upper case


#6

I also have the same problem…:confused:


#7

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


#8

thank you…:grinning:


#9

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”);


#11

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


#12

this is my problem :frowning:


#13

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:


#14

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


#16

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.


#17

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.


#18

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


#19

so, is this bug already fixed?


#20

Doesn’t seem like it


#21

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