Year 8 · Summer 2

Raid: App Forge · Lesson 4 of 5

Raid build: an app for a problem at school

ProjectTopic 14 Programming further

Year 8 · Raid: App Forge · Lesson 4 of 5

You will learn to

  • Use a stand-up to say what you did, what you will do next and what is blocking you.
  • Use a list in App Inventor to store many items under one name.
  • Create the must-have features in your brief one at a time, testing after each one.
  • Write a short log of what you built and what comes next.

Year 8 · Raid: App Forge · Lesson 4 of 5

Success criteria

You have got it when you can say:

  • I can give my stand-up in under a minute.
  • I can add an item to a list and show the whole list on the screen.
  • I can show one feature from our brief working on a phone.
  • I can write my log at the end of the lesson.

Year 8 · Raid: App Forge · Lesson 4 of 5

Retrieval starter

Questions from before. Write your answers, then show them.

  1. Last lesson

    In def area(w, h): … and a = area(4, 3), which are the arguments?

    A area and aB 4 and 3C w and h

    B. 4 and 3

  2. Last unit

    During bubble sort, a whole pass makes no swaps. This means…

    A The list is sorted: stopB Start again from the beginningC Do one more pass to be safe

    A. The list is sorted: stop

  3. Earlier this year

    In <img src="cat.png" alt="A sleeping cat">, alt is…

    A A CSS propertyB An attributeC A tag

    B. An attribute

Year 8 · Raid: App Forge · Lesson 4 of 5

Key words (1 of 2)

List
One name holding many values in order. Also called an array.
Index
An item's position in a list, counting from 0.
Subroutine
A named block of code you can call when needed.
Function
A subroutine that returns a value.

Year 8 · Raid: App Forge · Lesson 4 of 5

Key words (2 of 2)

Parameter
A placeholder in a subroutine for a value passed in.
Validation
Checking input is reasonable before using it.
Boundary data
Test data at the very edge of what's allowed.

The explanation · step 1 of 4 · part 1 of 2

The stand-up

A stand-up is a very short team meeting at the start of the lesson. Everyone stands, so it stays short.

Each person answers three questions:

  1. What did I do last lesson?
  2. What will I do today?
  3. Is anything blocking me?

A blocker is a problem that stops you, like a missing picture or a bug you cannot fix.

The explanation · step 1 of 4 · part 2 of 2

The stand-up (continued)

e.g.Example

'Last lesson I built the screen. Today I will make the Add button work. Blocker: I don't know how to store more than one task.'

★Remember

One minute each. Solve problems after the stand-up, not during it.

The explanation · step 2 of 4 · part 1 of 2

Lists in App Inventor

A list stores many items under one name, in order. You met lists in Scratch in Year 7.

BlockWhat it does
initialize global tasks to (create empty list)Makes an empty list called tasks
add items to listAdds an item to the end of a list
select list itemGets the item at an index, like 1
remove list itemTakes out the item at an index
length of listSays how many items the list holds

An index is an item's place number in the list.

The explanation · step 2 of 4 · part 2 of 2

Lists in App Inventor (continued)

★Remember

App Inventor counts list items from 1, like Scratch. Python counts from 0.

A ListView component shows a whole list on the screen, one item per line.

The explanation · step 3 of 4 · part 1 of 3

Worked example: the homework list

The screen has a text box (txtTask), a button (btnAdd) and a ListView (lvTasks).

initialize global tasks to (create empty list)

when btnAdd.Click
    add items to list  list: (get global tasks)  item: (txtTask.Text)
    set lvTasks.Elements to (get global tasks)
    set txtTask.Text to ("")

The explanation · step 3 of 4 · part 2 of 3

Worked example: the homework list (continued)

  1. The list starts empty when the app opens.
  2. The user types a task and presses Add.
  3. The text in the box goes onto the end of the list.
  4. The ListView shows the whole list again, with the new task.
  5. The text box is cleared, ready for the next task.
e.g.Example

Stretch: add a task only if the box is not empty. Use an if with not and the is empty text block.

The explanation · step 3 of 4 · part 3 of 3

Worked example: the homework list (continued)

!Watch out

Variables vanish when the app closes. To keep the list, save it with a TinyDB component. TinyDB stores data on the phone.

The explanation · step 4 of 4 · part 1 of 2

Build, test, log

  1. Pick one must-have feature from your brief.
  2. Build only that feature.
  3. Test it on the phone.
  4. It works? Save a checkpoint, then pick the next feature.
  5. At the end of the lesson, write your log.
★Remember

Projects → Checkpoint saves a copy that works. If a change breaks the app, open the checkpoint.

The explanation · step 4 of 4 · part 2 of 2

Build, test, log (continued)

e.g.Example

Log: 'Lesson 4: the Add button puts tasks in the list and shows them. Problem: empty tasks were added. Fixed with an is-empty check. Next: tick tasks off.'

Year 8 · Raid: App Forge · Lesson 4 of 5

Worked example

The list tasks holds: 'Maths p.12', 'Science poster', 'French words'. What does select list item with index 2 give? What is the list after remove list item with index 1?

  1. App Inventor counts from 1. Item 1 is 'Maths p.12'. Item 2 is 'Science poster'.
  2. So index 2 gives 'Science poster'.
  3. Removing index 1 takes out 'Maths p.12'.
  4. The list is now 'Science poster', 'French words'. Each item moves up one place.
  5. In Python the list starts at index 0. So index 2 would give 'French words'.

Year 8 · Raid: App Forge · Lesson 4 of 5

Quick quiz · 1 of 3

open("log.txt", "w") on a file that already holds 100 lines…

  1. A Wipes it first
  2. B Adds to the end
  3. C Gives an error

A. Wipes it first

"w" empties the file before writing. Use "a" to append.

Year 8 · Raid: App Forge · Lesson 4 of 5

Quick quiz · 2 of 3

The program runs but gives the wrong answer. That's a…

  1. A Syntax error
  2. B Logic error
  3. C Runtime error

B. Logic error

The code is valid and doesn't crash; the thinking is wrong. Only testing finds it.

Year 8 · Raid: App Forge · Lesson 4 of 5

Quick quiz · 3 of 3

Program runs but gives the wrong answer. That's a…

  1. A Syntax error
  2. B Logic error

B. Logic error

The code is valid; the thinking is wrong.

Year 8 · Raid: App Forge · Lesson 4 of 5

Exit ticket

Answer on paper before you go. Then check.

  1. In ["a", "b", "c"], the index of "c" is…

    A 2B 3C c

    A. 2 Counting starts at 0: a = 0, b = 1, c = 2.

  2. word = "Python". What is word[1:4]?

    A "Pyth"B "yth"C "ytho"

    B. "yth" Start at index 1 (y), stop before index 4 (o): y, t, h. That's 4 − 1 = 3 characters.