There are three links:
<div class="menu"> <a href="#" id="one" onclick="engine()">Rock</a> <a href="#" id="two" onclick="engine()">Paper</a> <a href="#" id="three" onclick="engine()">Scissors</a> The task, when clicking on one of the links, is to change (set) the value in the global variable userChoice.
var userChoice; // глобальная переменная function engineGame() { // ее вызываем при клике на ссылку document.getElementById('one').onclick = function() { userChoice = "rock"; alert("до вызова функции userChoice = " + userChoice); // rock } document.getElementById('two').onclick = function() { userChoice = "paper"; alert("до вызова функции userChoice = " + userChoice); // paper } document.getElementById('three').onclick = function() { userChoice = "scissors"; alert("до вызова функции userChoice = " + userChoice); //scissors } }; engineGame(); alert("после вызова функции userChoice = " + userChoice); // сразу выскакивает undefined :( Question: 1. Have I achieved the task? (set the value in a global variable) or is it done differently?