learn to generate random numbers and further knowledge on using if statements in JavaScript.
- generate random
- if statements
- Have three buttons that the player can press to change their pick
- Have another button to let the computer pick one and show the winner
- Let the player know they won (no alert box)
- Have a reset button
function showRock() {
document.getElementById("iconArea").innerHTML = rock;
document.getElementById("computerIconArea").innerHTML = " ";
document.getElementById("ResultTextArea").innerHTML = " ";
}
function showRandom() {
let computerChoice = [
'<i class="fas fa-hand-rock fa-4x" aria-hidden="true"></i>',
'<i class="fas fa-hand-paper fa-4x" aria-hidden="true"></i>',
'<i class="fas fa-hand-scissors fa-4x" aria-hidden="true"></i>'
];
let rand = computerChoice[Math.floor(Math.random() * computerChoice.length)];
document.getElementById("computerIconArea").innerHTML = rand;
}
function compareFields() {
if (playerResult === "<i class=\"fas fa-hand-rock fa-4x\" aria-hidden=\"true\"></i>"
&& computerResult === "<i class=\"fas fa-hand-paper fa-4x\" aria-hidden=\"true\"></i>") {
document.getElementById("ResultTextArea").innerHTML = "YOU LOSE!"
}
else if (playerResult === "<i class=\"fas fa-hand-rock fa-4x\" aria-hidden=\"true\"></i>"
&& computerResult === "<i class=\"fas fa-hand-scissors fa-4x\" aria-hidden=\"true\"></i>") {
document.getElementById("ResultTextArea").innerHTML = "YOU WIN!"
}
- Add a scoreboard
- Function compareFields doesn't compute when player has not made a choice
https://seppeverhavert.github.io/Schaar-Steen-Papier/
- Bootstrap 4
- Font-Awesome