Variables Intro 1 Solution

Exercises to introduce variables.
  1. Count (and show) how many times you click on the button sprite. Assume we have already made a “clicks” variable.

    
        When this sprite clicked
        change [clicks v] by (1)
        
    
  2. Reset the count of clicks to zero when you hit “r”.

    
        when [r v] key pressed
        set [clicks v] to (0)
        
    
  3. There is a “Mario” sprite and a “Coin” sprite.

    • Show on the screen how many coins Mario has touched.
    • When Mario touches a coin, it reappears in a random location.
    • Assume you have already made a “coins” variable.
    
        when green flag clicked
        forever
        if < touching [Mario v] > then
          change [coins v] by (1) 
          go to [random position v]
        
    
  4. Phil eats hamburgers. After he eats 5 burgers, he pixelates to “125”. When he eats 10 hamburgers, he “wins”. Have just one burger that reappears in a random position on the screen when Phil touches it.

    • Phil:
    
        when green flag clicked
        forever
        if < (burgers) = (5) > then
          set [pixelate v] effect to (125)
          end
        if < (burgers) = (10) > then
          broadcast [game over v]
          end
        
    
    • Burger:
    
        when green flag clicked
        forever
        if < touching [Phil v] > then
          change [burgers v] by (1) 
          go to [random position v]
        
    
Last modified August 18, 2023: 2022-2023 End State (7352e87)