Hey all,<\/p>\n
Just started learning powershell and decided the best way to learn was to make a few little games etc.<\/p>\n
The following is the fourth one I’ve made and works up until the point it tries to call the data from variables.<\/p>\n
It misses out the whole grading and ranking process and skips straight to the end screen.<\/p>\n
Any idea’s where I’m going wrong here?<\/p>\n
Thanks in advance<\/p>\n
#*************************************************************************************************************<\/p>\n
#**************************************************************************************************************<\/p>\n
#clear<\/span> screen #set<\/span> write-host as ds #define<\/span> variables used to store player answers #define<\/span> variable to keep track of correct answers #display<\/span> the games opening screen #pause<\/span> script #clear<\/span> screen #Provide<\/span> the player with instructions ds “ ds “ #pause<\/span> script #ask<\/span> the first question cls #clear<\/span> screen<\/p>\n ds #clear<\/span> screen #second<\/span> question cls #clear<\/span> screen<\/p>\n ds #clear<\/span> screen #third<\/span> question cls #clear<\/span> screen<\/p>\n ds #clear<\/span> screen #forth<\/span> question cls #clear<\/span> screen<\/p>\n ds #clear<\/span> screen #final<\/span> question cls #clear<\/span> screen<\/p>\n ds #end<\/span> game<\/p>\n #clear<\/span> screen ds #pause<\/span> script #clear<\/span> screen #grade<\/span> the answers for each question #assign<\/span> a ranking based on quiz score. if ($noCorrect -eq 1) { if ($noCorrect -eq 2) { if ($noCorrect -eq 3) { if ($noCorrect -eq 4) { if ($noCorrect -eq 5) { #clear<\/span> script #End<\/span> screen #pause<\/span> script #clear<\/span> screen I’m glad it wasn’t just me. Also replace all of those if statements concerning the score with a switch statement.<\/p>\n
\ncls<\/p>\n
\nset-alias ds write-host<\/p>\n
\n$question1 = “”
\n$question2 = “”
\n$question3 = “”
\n$question4 = “”
\n$question5 = “”<\/p>\n
\n$noCorrect = 0<\/p>\n
\nds “n<\/code>n
n<\/code>t
t WELCOME TO THE\" ds \"<\/code>n
n<\/code>t
t LORD OF THE RINGS\" ds \"<\/code>n
n<\/code>t
t TRIVIA QUIZ\" ds \"<\/code>n
n<\/code>n
t<\/code>t By P K Morgan”
\nds “n<\/code>n
n<\/code>n
n<\/code>t`t Press Enter To Continue”<\/p>\n
\nread-host<\/p>\n
\ncls<\/p>\n
\nds “n<\/code>n The Lord of the Rings trivia quiz tests your knowledge of
n\" ds \"Lord of the Rings trivia. The quiz consists of 5 multiple choice <\/code>n”
\nds “questions. At the end of the quiz, your answers will be checked and n\" ds \"you will be assigned a skill level using the following scale. <\/code>n`n”<\/p>\n
t<\/code>t Score: 5 correct = Gandalf (master)”
\nds “t<\/code>t Score: 4 correct = Aragorn”
\nds “t<\/code>t Score: 3 correct = Legolas”
\nds “t<\/code>t Score: 2 correct = Gimli”
\nds “t<\/code>t Score: 1 correct = Frodo”
\nds “t<\/code>t Score: 0 correct = Samwise (Clueless)”<\/p>\n
n<\/code>n
n<\/code>n`n Press Enter To Continue”<\/p>\n
\nread-host<\/p>\n
\nwhile (($question1 -ne “a”) -and ($question1 -ne “b”) -and ($question1 -ne “c”) -and ($question1 -ne “d”)) {<\/p>\n
\nds “What is the name of the character, that helps the Hobbits escape the old forest?”
\nds
\nds “A. Mithrandir”
\nds “B. Faramir”
\nds “C. Tom Bombadil”
\nds “D. Ham Gamgee”
\nds
\n$question1 = read-host “Type the letter representing the correct answer, and press the Enter key.”
\n}<\/p>\n
\ncls<\/p>\n
\nwhile (($question2 -ne “a”) -and ($question2 -ne “b”) -and ($question2 -ne “c”) -and ($question2 -ne “d”)) {<\/p>\n
\nds “What is the name of the first landmark the Hobbits visit?”
\nds
\nds “A. Weathertop”
\nds “B. The Prancing Pony”
\nds “C. Rivendell”
\nds “D. The Barrow Downs”
\nds
\n$question2 = read-host “Type the letter representing the correct answer, and press the Enter key.”
\n}<\/p>\n
\ncls<\/p>\n
\nwhile (($question3 -ne “a”) -and ($question3 -ne “b”) -and ($question3 -ne “c”) -and ($question3 -ne “d”)) {<\/p>\n
\nds “What is Aragorn called by the men of Bree?”
\nds
\nds “A. Strinder”
\nds “B. Longshanks”
\nds “C. Ranger”
\nds “D. The Dunedain”
\nds
\n$question3 = read-host “Type the letter representing the correct answer, and press the Enter key.”
\n}<\/p>\n
\ncls<\/p>\n
\nwhile (($question4 -ne “a”) -and ($question4 -ne “b”) -and ($question4 -ne “c”) -and ($question4 -ne “d”)) {<\/p>\n
\nds “What is the name given to the King of the Wood Elves?”
\nds
\nds “A. Elrond”
\nds “B. Thranduil”
\nds “C. Glorfindel”
\nds “D. Hunduin”
\nds
\n$question4 = read-host “Type the letter representing the correct answer, and press the Enter key.”
\n}<\/p>\n
\ncls<\/p>\n
\nwhile (($question5 -ne “a”) -and ($question5 -ne “b”) -and ($question5 -ne “c”) -and ($question5 -ne “d”)) {<\/p>\n
\nds “What is the correct name to describe Gandalf, Radaghast and Saruman?”
\nds
\nds “A. Sorcerers”
\nds “B. Wizards”
\nds “C. Warlocks”
\nds “D. Istari”
\nds
\n$question5 = read-host “Type the letter representing the correct answer, and press the Enter key.”
\n}<\/p>\n
\ncls<\/p>\n
\nds “OK, now press enter to see how you did!”<\/p>\n
\nread-host<\/p>\n
\ncls<\/p>\n
\nif ( $question1 -eq “c” ) { $noCorrect ++ } #Correct<\/span> answer is C
\nif ( $question2 -eq “d” ) { $noCorrect ++ } #Correct<\/span> answer is D
\nif ( $question3 -eq “a” ) { $noCorrect ++ } #Correct<\/span> answer is A
\nif ( $question4 -eq “b” ) { $noCorrect ++ } #Correct<\/span> answer is B
\nif ( $question5 -eq “d” ) { $noCorrect ++ } #Correct<\/span> answer is D<\/p>\n
\nif ($noCorrect -eq 0) {
\nds “n You didn't get any questions correct.\" ds \"<\/code>n`n Your knowledge of the world is no better than Samwise’s.”
\n}<\/p>\n
\nds “n You got 1 question correct.\" ds \"<\/code>n Like Frodo, you know a little about the world.”
\n}<\/p>\n
\nds “n You got 2 questions correct.\" ds \"<\/code>n You have done a small amount of travel, not unlike Gimli prior to the forming of the fellowship.”
\n}<\/p>\n
\nds “n You got 3 questions correct.\" ds \"<\/code>n Suilad, Mae govannan mellon! You are just like Legolas and possess a deep understanding that comes with lonng years.”
\n}<\/p>\n
\nds “n You got 4 correct.\" ds \"<\/code>n Long study of your ancestry have left you as knowledgable as Aragorn.”
\n}<\/p>\n
\nds “n Congratulation, you got 5 correct.\" ds \"<\/code>n Are you sure you’re not akin to Gandalf? You clearly possess the knowledge of one of the Istari!”
\n}<\/p>\n
\ncls<\/p>\n
\nds “n Thank you for playing <\/code>n”
\nds “The Lord of the Rings Trivia Quiz.”
\nds “`n Press Enter to Exit”<\/p>\n
\nread-host<\/p>\n
\ncls<\/p>","upvoteCount":1,"answerCount":5,"datePublished":"2017-01-24T17:07:38.000Z","author":{"@type":"Person","name":"perimorgan","url":"https://community.spiceworks.com/u/perimorgan"},"acceptedAnswer":{"@type":"Answer","text":"