Daniel Stolba
Published © CC0

Very Basic Addition Game

A simple game for the Calliope Mini that creates a random math task and lets the user solve it.

BeginnerShowcase (no instructions)12 minutes1,090
Very Basic Addition Game

Things used in this project

Story

Read more

Code

Simple Addition Game

JavaScript
Use the Calliope Mini Editor at pxt.calliope.cc, switch it to JavaScript and paste the code.
let loesung = 0
let aufgabe = ""
let add2 = 0
let tipp = 0
let add1 = 0
input.onButtonPressed(Button.AB, () => {
    add1 = 1 + Math.random(5)
    add2 = Math.random(5)
    aufgabe = "" + add1 + "+" + ("" + add2 + "=?")
    loesung = add1 + add2
    basic.showString(aufgabe)
    music.playTone(262, music.beat(BeatFraction.Whole))
    tipp = 0
    basic.showNumber(tipp)
})
input.onButtonPressed(Button.A, () => {
    tipp += 1
    basic.showNumber(tipp)
})
input.onButtonPressed(Button.B, () => {
    if (tipp == loesung) {
        tipp = 0
        basic.showIcon(IconNames.Happy)
        music.playTone(698, music.beat(BeatFraction.Quarter))
        music.rest(music.beat(BeatFraction.Eighth))
        music.playTone(698, music.beat(BeatFraction.Quarter))
        music.rest(music.beat(BeatFraction.Eighth))
        music.playTone(698, music.beat(BeatFraction.Quarter))
    } else {
        tipp = 0
        basic.showIcon(IconNames.Sad)
        music.playTone(165, music.beat(BeatFraction.Whole))
        music.playTone(131, music.beat(BeatFraction.Whole))
        basic.showString(aufgabe)
        basic.showNumber(tipp)
    }
})

Credits

Daniel Stolba

Daniel Stolba

0 projects • 1 follower

Comments