Create The Second Part Of A Rock Paper Scissors Game

Create The Second Part Of A Rock Paper Scissors Game Alter Lab 6 S

Create the second part of a Rock, Paper, Scissors game. Alter lab 6 so that the user keeps playing as long as they enter in 'Y'. Make this case sensitive; if they enter in lower case y the game will not continue. If the user enters in anything besides upper case Y the game will end. Your text must exactly match the examples below: Example 1 with correct input: Let's play Rock, Paper, Scissors Enter 1 for Rock, 2 for Paper, 3 for Scissors 2 You chose paper Would you like to play again (Y for yes, N for no)? Y Enter 1 for Rock, 2 for Paper, 3 for Scissors 1 You chose rock Would you like to play again (Y for yes, N for no)? N Example 2 with incorrect input: Let's play Rock, Paper, Scissors Enter 1 for Rock, 2 for Paper, 3 for Scissors 5 5 is not a valid choice Would you like to play again (Y for yes, N for no)? y ---------------------------------------------------------------------------------------------------------------- Create a program that asks the user what number they want the program to count up to. Have the program count from 1 to the number entered. Then have the program count down from the number entered to 1. What do you want me to count up to? 10 Up to Now back to

Paper For Above instruction

Create the second part of a Rock, Paper, Scissors game. Alter lab 6 so that the user keeps playing as long as they enter in 'Y'. Make this case sensitive; if they enter in lower case y the game will not continue. If the user enters in anything besides upper case Y the game will end. Your text must exactly match the examples below: Example 1 with correct input: Let's play Rock, Paper, Scissors Enter 1 for Rock, 2 for Paper, 3 for Scissors 2 You chose paper Would you like to play again (Y for yes, N for no)? Y Enter 1 for Rock, 2 for Paper, 3 for Scissors 1 You chose rock Would you like to play again (Y for yes, N for no)? N Example 2 with incorrect input: Let's play Rock, Paper, Scissors Enter 1 for Rock, 2 for Paper, 3 for Scissors 5 5 is not a valid choice Would you like to play again (Y for yes, N for no)? y

Paper For Above instruction

Create The Second Part Of A Rock Paper Scissors Game Alter Lab 6 S

Rock, Paper, Scissors Game with Play Again Feature

// Function to get user's choice for Rock, Paper, Scissors

function getUserChoice() {

let choice = prompt("Enter 1 for Rock, 2 for Paper, 3 for Scissors");

if (choice === null) {

return null; // User canceled

}

choice = choice.trim();

if (choice !== "1" && choice !== "2" && choice !== "3") {

alert(choice + " is not a valid choice");

return null;

}

return choice;

}

// Function to get user decision to continue

function getPlayAgain() {

let answer = prompt("Would you like to play again (Y for yes, N for no)?");

if (answer === null) {

return false; // User canceled

}

return answer.trim() === "Y";

}

// Main game function

function playGame() {

alert("Let's play Rock, Paper, Scissors");

let continuePlaying = true;

while (continuePlaying) {

let userChoice = getUserChoice();

if (userChoice === null) {

break; // Exit if invalid choice

}

// Map user's choice to text

let choicesText = { "1": "rock", "2": "paper", "3": "scissors" };

let userChoiceText = choicesText[userChoice];

alert("You chose " + userChoiceText);

// Generate computer choice

let computerChoiceNumber = Math.floor(Math.random() * 3) + 1;

let computerChoiceText = choicesText[computerChoiceNumber];

alert("Computer chose " + computerChoiceText);

// Determine winner

if (userChoice === computerChoiceNumber.toString()) {

alert("It's a tie!");

} else if (

(userChoice === "1" && computerChoiceNumber === 3) ||

(userChoice === "2" && computerChoiceNumber === 1) ||

(userChoice === "3" && computerChoiceNumber === 2)

) {

alert("You win!");

} else {

alert("Computer wins!");

}

// Ask if player wants to play again

let answer = prompt("Would you like to play again (Y for yes, N for no)?");

if (answer === null || answer !== "Y") {

continuePlaying = false;

}

}

alert("Thanks for playing!");

}

// Execute the game

playGame();

Counting Program: Count Up and Count Down

function countUpAndDown() {

let maxNumber = prompt("What do you want me to count up to?");

if (maxNumber === null) {

alert("No input provided. Exiting.");

return;

}

maxNumber = parseInt(maxNumber.trim(), 10);

if (isNaN(maxNumber) || maxNumber

alert("Invalid number entered.");

return;

}

// Count up

let countUpStr = "";

for (let i = 1; i

countUpStr += i + " ";

}

alert("Counting up: " + countUpStr.trim());

// Count down

let countDownStr = "";

for (let i = maxNumber; i >= 1; i--) {

countDownStr += i + " ";

}

alert("Counting down: " + countDownStr.trim());

}

// Run counting function

countUpAndDown();