What planet is the biggest string choicessize a

This preview shows page 43 - 46 out of 46 pages.

We have textbook solutions for you!
The document you are viewing contains questions related to this textbook.
JavaScript: The Web Warrior Series
The document you are viewing contains questions related to this textbook.
Chapter 2 / Exercise 4
JavaScript: The Web Warrior Series
Vodnik
Expert Verified
“What planet is the biggest?” string CHOICES[SIZE] = “A. Scopper, B. Dipper, C. Sun, D. Moon”, “A. Luna, B. Europa, C. Sol, D. Terra”, “A. 6, B. 93, C. 10, D. 35”, “A. 6, B. 2, C. 3, D. 1”, “A. Saturn, B. Jupiter, C. Earth, D. Mars” string ANSWERS[SIZE] = “C”, “A”, “A”, “C”, “B” x = 0 while x < SIZE guesses[x] = getAnswer(QUESTIONS[x], CHOICES[x]) correct = correct + displayAnswer(guesses[x], ANSWERS[x]) x = x + 1 endwhile output “Number of correct=”, correct output “Number of incorrect=”, (SIZE – correct) stop string getAnswer(string question, string choices) Declarations string answer output question output choices input answer while (answer not equal to “A” OR answer not equal to “B” OR answer not equal to “C” OR answer not equal to “D”) output question output choices input answer endwhile return answer 43
We have textbook solutions for you!
The document you are viewing contains questions related to this textbook.
JavaScript: The Web Warrior Series
The document you are viewing contains questions related to this textbook.
Chapter 2 / Exercise 4
JavaScript: The Web Warrior Series
Vodnik
Expert Verified
Programming Logic and Design, 8e Solutions 9- num displayAnswer(string guess, string answer) Declarations num correct = 0 if guess = answer then output “Correct!” correct = 1 else output “The correct answer is: ”, answer endif return correct 2. In the Game Zone section of Chapter 6, you designed the logic for the game Hangman, in which the user guesses letters in a hidden word. Improve the game to store an array of 10 words. One at a time, pass each word to a method that allows the user to guess letters continuously until the game is solved. The method returns the number of guesses it took to complete the word. Store the number in an array before returning to the method for the next word. After all 10 words have been guessed, display a summary of the number of guesses required for each word as well as the average number of guesses per word. 44
Programming Logic and Design, 8e Solutions 9- Declarations character letter num numCorrect num length num x num guesses // get the length of the word length = 0 while word[length] exists length = length + 1 endwhile // display dashes “-” x = 0 while x < LENGTH output “-” endwhile numCorrect = 0 output “Please guess a letter” input letter guesses = 1 while numCorrect <> length x = 0 while x < length if word[x] = letter then numCorrect = numCorrect + 1 output word[x] else output “-” endif x = x + 1 endwhile output “Please guess a letter” input letter guesses = guesses + 1 endwhile output “You guessed the word!” output word return guesses Up for Discussion

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture