FIX Declare a Read-Only Variable with the const Keyword

ES6: Declare a Read-Only Variable with the const Keyword

console.log should be changed to print the SENTENCE variable. The name of variable “sentence” is causing the problem which makes no sense.

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(SENTENCE);
  }

  // change code above this line

}
printManyTimes("freeCodeCamp");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 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

Your code works? But yes, this doesn’t make much sense, sentence isn’t accepted and the description does not tell you that the test will fail if you don’t change it to SENTENCE.

Yes, I have to change it to SENTENCE to get passed.

A common practice when naming constants is to use all uppercase letters, with words separated by an underscore.

Also, rename variables declared with const to conform to common practices, meaning constants should be in all caps.

It’s a listed requirment of the challenge.

1 Like

Ah, I missed that.

I’ve literally never done this for JS or worked anywhere that enforced it for JS, and given best practice is to use const for everything possible it means MOST PROGRAMS WOULD END UP READING LIKE THIS IF IT WAS ENFORCED, so it seems an extremely wierd constraint but 🤷 if people really like their JS code to look like COBOL I guess go for it

Edit: this is really bugging me, it’s definitely not best practice, all-caps indicates actual program constants that never change (like Pi, or gravity, or the speed of light in a vacuum), this is just a string that changes every time you run the function