' You can modify the number of seconds allowed and the math problems' upper limits.
' You can also independently change the math problem types' difficulties.
numberOfSecondsAllowed = 60
addFirstNumberUpperLimit = 9
addSecondNumberUpperLimit = 9
subtractFirstNumberUpperLimit = 9
subtractSecondNumberUpperLimit = 9
multiplyFirstNumberUpperLimit = 9
multiplySecondNumberUpperLimit = 9
divideFirstNumberUpperLimit = 99
divideSecondNumberUpperLimit = 9
TextWindow.WriteLine("You will have " + numberOfSecondsAllowed + " seconds to answer math problems.")
TextWindow.WriteLine("Select the type of problems, and then the timer will start.")
TextWindow.WriteLine("Do you want to answer (a)ddition, (s)ubtraction,")
TextWindow.WriteLine("(m)ultiplication, or (d)ivision problems?")
TextWindow.WriteLine("Press a, s, m, or d. Then press ENTER to start.")
choice = TextWindow.Read()
If choice = "a" Then
MakeGuesses()
ElseIf choice = "s" Then
MakeGuesses()
ElseIf choice = "m" Then
MakeGuesses()
ElseIf choice = "d" Then
MakeGuesses()
Else
TextWindow.WriteLine("I'm sorry, but I don't recognize that key. Please start over.")
EndIf
Sub MakeGuesses
Timer.Interval = 1000
Timer.Tick = OnTick
If guess = answer Then
correctAnswers = correctAnswers + 1
EndIf
attempts = attempts + 1
EndWhile
EndSub
Sub CompareNumbers
' Make sure that all subtraction answers are zero or greater.
' Make sure that all division answers are one or greater.
If firstNumber < secondNumber Then
temp = firstNumber
firstNumber = secondNumber
secondNumber = temp
EndIf
EndSub
Sub NoRemainders
' Make sure that all division answers are whole numbers (no fractions).
While Math.Remainder(firstNumber, secondNumber) > 0
firstNumber = Math.GetRandomNumber(divideFirstNumberUpperLimit)
secondNumber = Math.GetRandomNumber(divideSecondNumberUpperLimit)
CompareNumbers()
EndWhile
EndSub
Sub ShowResults
TextWindow.WriteLine("")
TextWindow.WriteLine("Time's up! You answered " + correctAnswers + " out of " + attempts + " correctly (" + Math.Round((correctAnswers / attempts) * 100) + "%).")
EndSub
Sub OnTick
elapsedSeconds = elapsedSeconds + 1
If elapsedSeconds = numberOfSecondsAllowed Then
ShowResults()
EndIf
EndSub