Seeking Guidance: Challenges with Test Cases at Step 92 in FreeCodeCamp's Basic JavaScript Course

function buyWeapon() {
  if (gold >= 30) {
    gold -= 30;
    currentWeapon++;
    goldText.innerText = gold;
    let newWeapon = weapons[currentWeapon].name;
    // text.innerText += "\nYou now have a " + newWeapon + "." + "\nIn your inventory you have: ";

    text.innerText += " \nIn your inventory you have: "

    inventory.push(newWeapon);

  }
}

Up until now, any time text.innerText was updated, the old text was erased. This time, use the += operator to add text to the end of text.innerText.

Add the string In your inventory you have: - include the spaces at the beginning and the end.

Even after this it’s showing " You should add a new line with text.innerText ."
Can anyone tell what’s the actual problem here.

use backticks and start the string going to a new line

It worked. Can you please tell me in brief, how this approach works and what’s the main issue in my provided answer.

the tests don’t recognise the new line character as a correct answer, it’s probably going to be changed… remember this is still a beta course, it’s being perfected as feedback come in

1 Like

In addition to @ilenia’s answer, it shows you that a template literal string recognizes a return/enter key as a legitimate character. I actually think this feature of the tests should be kept in the lesson but with additional help guidance and explanation.

But for this step, a new line is not required, which is why your test is failing. We want to create a single text line with two sentences (just like this paragraph).

In code, we would write my previous paragraph:

let myText = "But for this step, a new line is not required, which is why your test is failing.";
myText+=" We want to create a single text line with two sentences (just like this paragraph).";

Notice that for my second sentence, I add the space at the beginning. I could have also added it to the end of the first sentence. Or I could have said myText+=" "+“We want…”

1 Like

I agree to this. If there is a hint section then it might be helpful to us.