Question
a) Write a Javascript Program that prompts user repeatedly to input any number between 0 to 9. If the user inputs any number which is
a) Write a Javascript Program that prompts user repeatedly to input any number between 0 to 9. If the user inputs any number which is less than 0 ORgreater than 9 then the program should stop asking the user for inputand display Number not in range. Use Starter File to Create a program save it as Q1a.html file (Marks 16)
Hint 1 : use break statement with if condition Example : if(userInput<0){ document.write(Number not in range); break;// this stops the loop from executing again }
(Hint 2: use do while loop to achieve repeated prompts refer to Week 4, you can also use infinite for loop)
b) Convert the following Psueodocode to Javascript Program Start //Variable initiation Declare String playerOneName Declare Numeric playerOneScore Declare String playerTwoName Declare Numeric playerTwoScore Declare String playerThreeName Declare Numeric playerThreeScore Declare Numeric teamTotalScore Declare Numeric averageScorePerPlayer Declare Numeric playerOneDiffAvg Declare Numeric playerTwoDiffAvg Declare Numeric playerThreeDiffAvg // Input Display Enter Player One Name Input playerOneName Display Enter Player One Score Input playerOneScore //(Hint : use parse Int to parse the user input to integer in Javascript : // Example:playerOneScore=parseInt(playerOneScore);) Display Enter Player Two Name Input playerTwoName Display Enter Player Two Score Input playerTwoScore //(Hint : use parse Int to parse the user input to integer in Javascript ) Display Enter Player Three Name Input playerThreeName Display Enter Player Three Score Input playerThreeScore //(Hint : use parse Int to parse the user input to integer in Javascript ) //Process teamTotalScore= playerOneScore+playerTwoScore+ playerThreeScore averageScorePerPlayer = teamTotalScore/3 playerOneDiffAvg= averageScorePerPlayer- playerOneScore playerTwoDiffAvg= averageScorePerPlayer- playerTwoScore playerThreeDiffAvg= averageScorePerPlayer- playerThreeScore //Output
Display Total :+teamTotalScore+
Display Average score Per Player +averageScorePerPlayer+
Display Player Name: +playerOneName+
Display Scored : + playerOneScore+
Display Comparison to average Score:+playerOneDiffAvg+
Display Player Name: +playerTwoName+
Display Scored : + playerTwoScore+
Display Comparison to average Score:+playerTwoDiffAvg+
Display Player Name: +playerThreeName+
Display Scored : + playerThreeScore+
Display Comparison to average Score:+playerThreeDiffAvg+
Stop Use Starter File to Create a program Save it as Qb.html file (Marks 36)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started