Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 13, 2022 04:10 am GMT

Need help with The Odin's Project, Rock Paper Scissors assignment

I have been beating my brains out for the past few days trying to figure out why the functions being called are undefined.

Live Site
code

Here is how the console.log looks at the start of the game:

Starting the game

Expected Outcome:

When the playRound() is called, the if/else statements should be console.logging the correct statements. Like so:

const playRound = (playerSelection, computerSelection) => {  playerSelection = playerWeapon();  computerSelection = selectedWeapons();  console.log("playerWeapon: ", playerSelection);  console.log("computerWeapon: ", computerSelection);  if (computerSelection === "" && playerSelection === "") {    console.log("Computer Wins!");  } else if (playerSelection === "" && computerSelection === "") {    console.log("You Win!");  }  if (computerSelection === "" && playerSelection === "") {    console.log("Computer Wins!");  } else if (playerSelection === "" && computerSelection === "") {    console.log("You Win!");  }  if (computerSelection === "" && playerSelection === "") {    console.log("Computer Wins!");  } else if (playerSelection === "" && computerSelection === "") {    console.log("You Win!");  }  if (computerSelection === playerSelection) {      console.log("Tie!");  }}

Once I am able to get the code working properly, I will then use DOM manipulation, to have the game results displayed on the webpage instead of the console.

Current Outcome:

In the playRound(), I am calling both the selectedWeapons() and playerWeapon(). But both of the functions, are undefined and I am unable to get the values in the playRound() to use for the if/else statements. BUT, the only console.log message that's given is "Tie".Why is that?

I tried creating other functions, calling functions in other functions.I've also been playing around with the for..loops and event listeners.

Here is the console.log after playing a few rounds:

After playing a few rounds

Any help is greatly appreciated.


Original Link: https://dev.to/taepal467/need-help-with-the-odins-project-rock-paper-scissors-assignment-19ie

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To