Skip to content

Guess the Number

cl4cnam edited this page Jan 16, 2024 · 2 revisions

In this tutorial, you'll learn to program a little well known game "Guess the Number".

Prepare your environment

Do as in Hello World tutorial except that you change the names: guessTheNumber, guessTheNumber.html, guessTheNumber.fg.

Write the program

Write these lines into guessTheNumber.fg:

var numberToGuess := randomIntBetween(1, 100)
var triedNumber := 0
displayNewMessage('Guess my number (between 1 and 100)!')

while triedNumber != numberToGuess:
	
	triedNumber := awaitHumanText()
	
	if triedNumber < numberToGuess:
		displayNewMessage('Too low! Try again!')
	if triedNumber > numberToGuess:
		displayNewMessage('Too high! Try again!')
	if triedNumber = numberToGuess:
		displayNewMessage('Well Done!')

Note

This is programmed like when you first learned programming! 👍

⏮️ Previous tutorial      ⏭️ Next tutorial