INQ241B
Mobile Apps

Final Review

A Miniature Practice Final Exam

  1. Draw what the following script would draw when run:

    function main()
      ◳angle := 0
      ▷go(25)
      ▷go(50)
    end function
    
    function go(
      distance : Number)
    do
      turtle→forward(distance * 2)
      ◳angle := ◳angle + 45
      turtle→left turn(◳angle)
    end function
  2. For the following script:

    function main()
      var board := ♻game→start
      var rectangle := create rectangle(100, 100)
      rectangle→set pos(rectangle→width / 2, board→height / 2)
      board→add on every do
          ▷update(rectangle)
      end
    end function
    
    function update(
      sprite : Sprite)
    do
      sprite→set x(sprite→x + 10)
      if sprite→right > board→width then
        sprite→set left(0)
      else do nothing end if
    end function
    1. Draw what will be displayed when the app first starts.

    2. Describe what will happen when the app runs.

  3. For the following script:

    page main ()
    initialize
      ◳count := 0
    display
      boxed
        box→set width(10)
        box→set height(10)
        if ◳count = 0 then
          box→set background(colors→black)
        else
          box→set border(colors→black, 0.1)
        end if
        box→on tapped(handler)
          where handler() is
            ◳count := ◳count + 1
            if ◳count = 2 then
              ◳count := 0
            else do nothing end if
        end
      end boxed
    end page
    1. Draw what will be displayed when the app first starts.

    2. Describe what will happen when the user presses the button multiple times.