Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

The 2nd object in the questions array’s choices are [“”, “

”, “”], for some reason when this object gets picked, the choices and answer get converted to empty strings, so when the function selects this object and logs it to the console, the choices array is 3 empty strings and the answer is an empty string, I thought this was a JavaScript thing where we can’t use < or > but it worked in CodePen, I think this a bug within freeCodeCamp.

Your code so far

const questions = [
  {
    category: "JavaScript",
    question: "Which keyword is used to declare a variable that cannot be reassigned?",
    choices: ["let", "const", "var"],
    answer: "const"
  },
  {
    category: "HTML",
    question: "Which tag is used to create a hyperlink?",
    choices: ["<a>", "<p>", "<img>"],
    answer: "<a>"
  },
  {
    category: "CSS",
    question: "Which property is used to change text color?",
    choices: ["font-size", "color", "background-color"],
    answer: "color"
  },
  {
    category: "Programming",
    question: "What does JSON stand for?",
    choices: ["Java Source Object Notation", "JavaScript Object Notation", "Java Structured Output Network"],
    answer: "JavaScript Object Notation"
  },
  {
    category: "Web",
    question: "Which of these is a JavaScript framework/library?",
    choices: ["React", "Photoshop", "MySQL"],
    answer: "React"
  }

];

function getRandomQuestion(arr){
  return arr[Math.floor(Math.random() * 4)];
}

function getRandomComputerChoice(arrChoices){
  return arrChoices[Math.floor(Math.random() * 3)];
}

function getResults(questionObj, computerChoice){
  if(computerChoice === questionObj.answer){
    return "The computer's choice is correct!";
  } else if (getRandomComputerChoice(computerChoice) !== questionObj.answer){
    return `The computer's choice is wrong. The correct answer is: ${questionObj.answer}`;
  }
}

const randomObjq = getRandomQuestion(questions);
const randomc = getRandomComputerChoice(randomObjq.choices);
console.log(`The Object picked: ${JSON.stringify(randomObjq, null, 2)}`);
console.log(`The answer picked: ${randomc}`);
console.log(getResults(randomObjq, randomc));


Your browser information:

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

Challenge Information:

Build a Quiz Game - Build a Quiz Game

\["<a>", "<p>", "<img>"\]

I can’t even type them here on the forums

Hi @GhadyKeyrouz ,

I edited your post to show the HTML tags you included as question choices.

There is no bug. These tags are being parsed, which is normal browser behavior.

Change your question choices to move forward with this challenge.

Happy coding!