I am testing my code and I can't figure out why it's not working.
I created buttons in HTML for each choice and created a function in JavaScript for each choice. I included onclick in HTML to call the respective functions and try to log the choice in the console so I could see if it was working but nothing happens when I click the userRock button.
I would greatly appreciate some help. Thank you.
let userChoice;
function userRock () {
userChoice = 'rock';
return userChoice;
console.log(userChoice);
}
function userPaper () {
userChoice = 'paper';
return userChoice;
}
function userScissors () {
userChoice = 'scissors';
return userChoice;
}
function userLizard () {
userChoice = 'lizard';
return userChoice;
}
function userSpock () {
userChoice = 'spock';
return userChoice;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Rock, Paper, Scissors, Lizard, Spock</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class = "container">
<button id = "rock" onclick = "userRock()">Rock</button> <button id = "paper" onclick = "userPaper()">Paper</button> <button id = "scissors" onclick = "userScissors()">Scissors</button> <button id = "lizard" onclick = "userLizard()">Lizard</button> <button id = "spock" onclick = "userSpock()">Spock</button>
</div>
<script src="scripts.js"></script>
</body>
</html>
Link to codepen: https://codepen.io/zenturtle/pen/YzqXVbB?editors=1111