Learn to code for kids and teens. Build a guessing game in Javascript

What is Code?

Simply put, code is something that you write to tell computers what to do. If you want to send a rocket to mars, you write code to tell computers how to do that. If you want to make a place for all of your friends to hang out online like Discord or Instagram, you write code. Maybe you want to build a game like Call of Duty, Apex Legends, or Stardew Valley? Then you write code.

Photo by Hello Lightbulb on Unsplash

How do you write code?

Code is written in different languages (you can think of it a bit like learning French vs. learning English). There are many popular languages out there, and each one is more suitable for different purposes. For this game, you’re going to use Javascript. Javascript is a programming language that is used by almost all websites (about 97.2%)

Let’s build a game together.

Follow the numbered instructions to start building a game!

let
let myFavoriteAnimal
let myFavoriteAnimal = "dog"
function
function guessMyFavoriteAnimal
function guessMyFavoriteAnimal()
function guessMyFavoriteAnimal(playerGuess)
function guessMyFavoriteAnimal(playerGuess) {}
function guessMyFavoriteAnimal(playerGuess) {
let myFavoriteAnimal = "dog"
}
function guessMyFavoriteAnimal(playerGuess) {
let myFavoriteAnimal = "dog"
if
}
function guessMyFavoriteAnimal(playerGuess) {
let myFavoriteAnimal = "dog"
if ()
}
function guessMyFavoriteAnimal(playerGuess) {
let myFavoriteAnimal = "dog"
if (myFavoriteAnimal)
}
function guessMyFavoriteAnimal(playerGuess) {
let myFavoriteAnimal = "dog"
if (myFavoriteAnimal ===)
}
function guessMyFavoriteAnimal(playerGuess) {
let myFavoriteAnimal = "dog"
if (myFavoriteAnimal === playerGuess)
}
function guessMyFavoriteAnimal(playerGuess) {
let myFavoriteAnimal = "dog"
if (myFavoriteAnimal === playerGuess) {

}
}
function guessMyFavoriteAnimal(playerGuess) {
let myFavoriteAnimal = "dog"
if (myFavoriteAnimal === playerGuess) {
console.log("Congrats! You got it right!")
}
}
function guessMyFavoriteAnimal(playerGuess) {
let myFavoriteAnimal = "dog"
if (myFavoriteAnimal === playerGuess) {
console.log("Congrats! You got it right!")
}
}
function guessMyFavoriteAnimal(playerGuess) {
let myFavoriteAnimal = "dog"
if (myFavoriteAnimal === playerGuess) {
console.log("Congrats! You got it right!")
} else {

}
}
function guessMyFavoriteAnimal(playerGuess) {
let myFavoriteAnimal = "dog"
if (myFavoriteAnimal === playerGuess) {
console.log("Congrats! You got it right!")
} else {
console.log("You got it wrong, try again!")
}
}
guessMyFavoriteAnimal
guessMyFavouriteAnimal()
guessMyFavoriteAnimal("cat")
guessMyFavoriteAnimal("cats")
guessMyFavoriteAnimal("")

Further Learning

Well done! You finished this lesson, and you’ve also made your own game in Javascript!

  • Can you make the correct answer random?
  • Can you write code that would guess every number between 1 and 10? what about 100? (hint: this probably uses for loops)
  • Can you alter the guess a number function to have to player answer math questions instead?

Other Resources

Khan Academy intro to programming https://www.khanacademy.org/computing/computer-programming/programming#intro-to-programming

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Brooklin Myers

Brooklin Myers

Software Engineer. I create educational content focused on technology for mobile and web applications.