samedi 7 mars 2020

VBScript not accepting else/elseif

I am trying to improve my script for a rock, paper, scissors game in VBScirpt. the book asks to add a way to have a winner determined. I was able to get the script to work by adding multiple if/then statements but i wanted to try and use else/elseif to make it more efficient. however when i use else/elseif the script fails. neither my instructor or can figure out why this is happening. especially since my other scripts are able to use these statements. Any help is appreciated.

Here is my script:

'Formally declare variables used by the script before trying to use them

Dim WshShl, Answer, CardImage


'Create an instance of the WScript object in order to later use the
'Popup method
Set WshShl = WScript.CreateObject("WScript.Shell")

'Display the rules of the game
WshShl.Popup "Welcome to the Rock, Paper, and Scissors game. Here are the " & _
    "rules of the game: 1. Guess the same thing as the computer " & _
    "to tie. 2. Paper covers rock and wins. 3. Rock breaks " & _
    "scissors and wins. 4. Scissors cut paper and win."

'Prompt the user to select a choice

Answer = InputBox("Type Paper, Rock, or Scissors.", _
    "Let's play a game!")

'Time for the computer to rando pick a choice
Randomize
GetRandomNumber = Int((3 * Rnd()) + 1)

'Assign a value to the ramdomly selected number
If GetRandomNumber = 3 then CardImage = "ROCK"
If GetRandomNumber = 2 then CardImage = "SCISSORS"
If GetRandomNumber = 1 then CardImage = "PAPER"

'Display the game's results so that the user can see if he or she won
WshShl.Popup "You picked: " & Answer & Space(12) & "Computer picked: " & _
    CardImage

'Results screen

If UCase(Answer) = CardImage Then _
    WshShl.Popup "It's a tied game!"
elseif UCase(Answer) = "ROCK" And CardImage = "SCISSORS" Then _
    WshShl.Popup "You Win!"
elseIf UCase(Answer) = "ROCK" And (CardImage = "PAPER") Then _
    WshShl.Popup "You Lose!"
elseIf UCase(Answer) = "PAPER" And (CardImage = "SCISSORS") Then _
    WshShl.Popup "You Lose!"
elseIf UCase(Answer) = "PAPER" And (CardImage = "ROCK") Then _
    WshShl.Popup "You Win!"
elseIf UCase(Answer) = "SCISSORS" And (CardImage = "ROCK") Then _
    WshShl.Popup "You Lose!"
else If UCase(Answer) = "SCISSORS" And (CardImage = "PAPER") Then _
    WshShl.Popup "You Win"
else
    WshShl.popup "c'mon"

Aucun commentaire:

Enregistrer un commentaire