You are going to create a simple program that asks the user how old they are. If they are over 18 it will say "Wow you are old!" and if they are under 18 it will say "What a great age to be!"
1. Open Small Basic.
2. Use TextWindow.WriteLine() to display the text "How old are you?"
3. Use TextWindow.Read() to take the user input and store it in a variable called age.
4. Now copy the code below to create an if statement to decide which message to display:
If age > 18 Then
TextWindow.WriteLine("Wow you are old!")
Else
TextWindow.WriteLine("What a great age to be!")
EndIf
5. Run you program and test it to check that it works.
Using the program you have just made you are going to improve it so that it checks more than one age group.
The work should work by:
Checking if the age is older than 19 and say "Wow you are old!" if they are
If they are not more than 19 it should check to see if they are older than 12 and say "Hey there teenager!" if they are
If they are not over 19 or 12 then it should say "Hey there youngster!"
NOTE: You will need to change the program you started, not start a new program.
Below is what an If can look like when using ElseIf:
TextWindow.WriteLine("What colour is the traffic light?")
colour = TextWindow.Read()
If colour = "Red" Then
TextWindow.WriteLine("STOP")
ElseIf colour = "Amber" Then
TextWindow.WriteLine("GET READY")
Else
TextWindow.WriteLine("GO")
EndIf
How well do you know the order of the planets? Well, we are about to find out! You are going to create a Planet Quiz. The planet quiz should ask the user five questions about the order of the planets. For each question it should have 4 possible answers and only one will be correct. An example of how one question could look is shown to the left.
Use the help below to get started:
Display some text using TextWindow.WriteLine(), welcoming the user to the quiz
Display some text using TextWindow.WriteLine(), asking the user question 1 with the possible answers.
Store the user's answer using TextWindow.Read() in a variable called answer
Check to see if the answer is equal to the correct answer e.g. A,B,C or D
If it is display Correct, if it isn't display Wrong and tell them the correct answer.
Now use the code you have just made, copy it and adjust it for the second question and so on.
Can you change the colours so that each question uses a different foreground colour?
Can you keep track of the score? HINT: to do this you will need to set a variable called score to 0 at the start. Each time they get an answer right it should add 1 to the score (score = score + 1)