On Friday, I completed the Rock, Paper, Scissors project. Overall, it wasn’t too challenging, but I encountered an issue getting the game to play on the console. I don’t know what I was doing wrong. Today, we’re practicing some Javascript exercises involving loops and arrays, and I’m still working on them.
Tommy is making a cat tree for the cats. On Saturday, we had a long day of getting the supplies for the cat tree. We had to go to two Home Depots and the city twice since we had to return to our town after the first Home Depot trip for his haircut. Customer service at the first Home Depot could have been better. The lady just seemed offputting.
On Sunday, we celebrated my birthday with a delicious dinner of street tacos. Kel baked a cake for me with a unicorn horn and ears that looked adorable. I received lovely gifts, including sheet masks, a new cup, and a Hello Kitty air tag holder. Although it’s meant for an air tag, I’ll use it to hold my medallion from the cruise ship.
Speaking of the cruise ship, our trip starts at the end of next month. I need to look for some things that I’m missing, like my bathing suit and rain jacket. Maybe I can do that right now…
JavaScript notes…
———————————-
/* Rock, Paper, Scissors */ function getComputerChoice() { const randomNumber = Math.floor(Math.random() * 3); if (randomNumber === 0) { return "rock"; } else if (randomNumber === 1) { return "paper"; } else { return "scissors"; } } function getHumanChoice() { let choice = prompt("Please enter rock, paper or scissors").toLowerCase(); while (choice !== "rock" && choice !== "paper" && choice !== "scissors") { choice = prompt("Invalid choice. Please enter rock, paper, or scissors.").toLowerCase(); } return choice; } function playRound(humanChoice, computerChoice) { humanChoice = humanChoice.toLowerCase(); if (humanChoice === computerChoice) { console.log("It's a tie!") } else if ((humanChoice === "rock" && computerChoice === "scissors") || (humanChoice === "paper" && computerChoice === "rock") || (humanChoice === "scissors" && computerChoice === "paper")) { humanScore++; console.log(`You win! ${humanChoice.charAt(0).toUpperCase() + humanChoice.slice(1)} beats ${computerChoice}.`); } else { computerScore++; console.log(`You lose! ${computerChoice.charAt(0).toUpperCase() + computerChoice.slice(1)} beats ${humanChoice}.`); } console.log(`Human Score: ${humanScore}, Computer Score: ${computerScore}`); } function playGame() { let humanScore = 0; let computerScore = 0; for (let i = 0; i < 5; i++) { const humanChoice = getHumanChoice(); const computerChoice = getComputerChoice(); const roundResult = playRound(humanChoice, computerChoice); if (roundResult === "human") { humanScore++; } else if (roundResult === "computer") { computerScore++; } console.log(`Round ${i + 1} - Human Score: ${humanScore}, Computer Score: ${computerScore}`); } if (humanScore > computerScore) { console.log(`Congratulations! You win the game with a score of ${humanScore} to ${computerScore}.`); } else if (computerScore > humanScore) { console.log(`Sorry, you lose. The computer wins the game with a score of ${computerScore} to ${humanScore}.`); } else { console.log(`It's a tie game! Both you and the computer scored ${humanScore}.`); } } playGame();