Review DOM Manipulation by Building a Rock, Paper, Scissors Game - Step 3

Tell us what’s happening:

Why is a template literal being used here in the answers on the forum the question just asked to input the userOption and computerResult

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

function getRoundResults(userOption) {
  const computerResult = getRandomComputerResult();
 if (hasPlayerWonTheRound (userOption, computerResult)) {
   playerScore.Update += 1;
 return "Player wins! userOption beats computerResult";
 }

 if(userOption === computerResult){
   return "It's a tie! Both chose userOption";
 }

 else{
   computerScore.Update += 1;
   return "Computer wins! computerResult beats userOption";
 }
}

console.log(getRoundResults("Rock"));
console.log("Player Score: ", playerScore, "Computer Score: ", computerScore);

// User Editable Region

Your browser information:

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

Challenge Information:

Review DOM Manipulation by Building a Rock, Paper, Scissors Game - Step 3

Hi there!

Without using template literals or concatenation, your variables are run as string text within a string.
Edit: also JavaScript doesn’t has an .Update property that you are using for updating value.

How do you know when to use template literals

I like to use those whenever I need to put the value of a variable in a string

When you’re using variables and functions within the string.

I tried this and it still did not work, any ideas why?


function getRoundResults(userOption) {
  const computerResult = getRandomComputerResult();
 if (hasPlayerWonTheRound (userOption, computerResult)) {
   playerScore += 1;
 return `"Player wins! ${userOption} beats ${computerResult}"`;
 }

 else if(userOption === computerResult){
   return `"It's a tie! Both chose ${userOption}"`;
 }

 else {
   computerScore += 1;
   return `"Computer wins! ${computerResult} beats ${userOption}";
 }
}

console.log(getRoundResults("Rock"));
console.log("Player Score: ", playerScore, "Computer Score: ", computerScore);

Nevermind, the templar literal at the last ${userOption} was missing, all sorted!

1 Like