← Debugging: find the bug line lesson New set →

App Dev Worksheet: Debugging

App development lesson 21: Debugging: find the bug line · Set 319 · 40 questions
TalentJR

Developer's tip (Compare with the comment): Read each line and its comment (after //): does the code do exactly that? Actual = run the lines as written. Expected = follow every comment. After the fix, test again.

NameDateTime takenScore ___ / 40
  1. 1.🐞 What is a good first step when an app gives a wrong result? (a) buy a new phone (b) add more colours (c) delete the app (d) find where it goes wrong
  2. 2.🐞 This code has a bug. What number SHOULD it show, if every line did what its comment says?
    line 1: let score = 35; // start at 33
    line 2: score = score * 2; // double it
    line 3: score = score * 2; // double it
    line 4: score = score - 5; // take away 5
    line 5: show(score); // show it
  3. 3.🐞 Each comment says what its line SHOULD do. Which line has the bug?
    line 1: let score = 34; // start at 34
    line 2: score = score + 1; // take away 1
    line 3: score = score * 2; // double it
    line 4: show(score); // show it
    (a) line 1 (b) line 3 (c) line 2
  4. 4.🐞 Each comment says what its line SHOULD do. Which line has the bug?
    line 1: let points = 34; // start at 34
    line 2: points = points + 4; // take away 4
    line 3: points = points - 2; // take away 2
    line 4: show(points); // show it
    (a) line 2 (b) line 3 (c) line 1
  5. 5.🐞 This code has a bug. What number does it ACTUALLY show?
    line 1: let stars = 48; // start at 48
    line 2: stars = stars + 2; // double it
    line 3: stars = stars - 5; // take away 5
    line 4: stars = stars - 2; // take away 2
    line 5: show(stars); // show it
  6. 6.🐞 Finding and fixing bugs is called ___. (a) decorating (b) designing (c) debugging (d) downloading
  7. 7.🐞 Each comment says what its line SHOULD do. Which line has the bug?
    line 1: let lives = 46; // start at 46
    line 2: lives = lives - 5; // take away 5
    line 3: lives = lives + 2; // double it
    line 4: lives = lives * 2; // double it
    line 5: show(lives); // show it
    (a) line 3 (b) line 4 (c) line 1 (d) line 2
  8. 8.🐞 Each comment says what its line SHOULD do. Which line has the bug?
    line 1: let lives = 43; // start at 43
    line 2: lives = lives - 4; // add 4
    line 3: lives = lives * 2; // double it
    line 4: lives = lives * 2; // double it
    line 5: show(lives); // show it
    (a) line 4 (b) line 3 (c) line 2 (d) line 1
  9. 9.🐞 This code has a bug. What number SHOULD it show, if every line did what its comment says?
    line 1: let stars = 43; // start at 41
    line 2: stars = stars + 6; // add 6
    line 3: stars = stars - 3; // take away 3
    line 4: show(stars); // show it
  10. 10.🐞 This code has a bug. What number does it ACTUALLY show?
    line 1: let stars = 38; // start at 38
    line 2: stars = stars * 2; // double it
    line 3: stars = stars * 3; // double it
    line 4: stars = stars + 4; // add 4
    line 5: show(stars); // show it
  11. 11.🐞 After fixing a bug you should ___. (a) delete the test (b) never test (c) release at once (d) test it again
  12. 12.🐞 This code has a bug. What number SHOULD it show, if every line did what its comment says?
    line 1: let coins = 47; // start at 46
    line 2: coins = coins * 2; // double it
    line 3: coins = coins - 4; // take away 4
    line 4: show(coins); // show it
  13. 13.🐞 This code has a bug. What number SHOULD it show, if every line did what its comment says?
    line 1: let coins = 48; // start at 48
    line 2: coins = coins - 4; // take away 4
    line 3: coins = coins + 7; // add 4
    line 4: show(coins); // show it
  14. 14.🐞 Each comment says what its line SHOULD do. Which line has the bug?
    line 1: let coins = 49; // start at 47
    line 2: coins = coins - 5; // take away 5
    line 3: coins = coins * 2; // double it
    line 4: coins = coins - 3; // take away 3
    line 5: show(coins); // show it
    (a) line 3 (b) line 1 (c) line 2 (d) line 4
  15. 15.🐞 This code has a bug. What number SHOULD it show, if every line did what its comment says?
    line 1: let score = 32; // start at 32
    line 2: score = score - 5; // take away 5
    line 3: score = score - 2; // add 2
    line 4: show(score); // show it
  16. 16.🐞 This code has a bug. What number SHOULD it show, if every line did what its comment says?
    line 1: let stars = 36; // start at 34
    line 2: stars = stars * 2; // double it
    line 3: stars = stars * 2; // double it
    line 4: show(stars); // show it
  17. 17.🐞 What is a bug? (a) a fast phone (b) a mistake in the code (c) a nice icon (d) a new feature
  18. 18.🐞 This code has a bug. What number SHOULD it show, if every line did what its comment says?
    line 1: let stars = 50; // start at 50
    line 2: stars = stars * 2; // double it
    line 3: stars = stars + 4; // take away 4
    line 4: stars = stars - 2; // take away 2
    line 5: show(stars); // show it
  19. 19.🐞 This code has a bug. What number does it ACTUALLY show?
    line 1: let score = 32; // start at 31
    line 2: score = score + 5; // add 5
    line 3: score = score + 3; // add 3
    line 4: show(score); // show it
  20. 20.🐞 This code has a bug. What number does it ACTUALLY show?
    line 1: let coins = 35; // start at 35
    line 2: coins = coins - 4; // take away 3
    line 3: coins = coins + 5; // add 5
    line 4: coins = coins - 1; // take away 1
    line 5: show(coins); // show it
  21. 21.🐞 This code has a bug. What number does it ACTUALLY show?
    line 1: let score = 44; // start at 44
    line 2: score = score + 3; // take away 3
    line 3: score = score + 6; // add 6
    line 4: show(score); // show it
  22. 22.🐞 This code has a bug. What number SHOULD it show, if every line did what its comment says?
    line 1: let points = 35; // start at 32
    line 2: points = points * 2; // double it
    line 3: points = points + 6; // add 6
    line 4: show(points); // show it
  23. 23.🐞 Each comment says what its line SHOULD do. Which line has the bug?
    line 1: let lives = 50; // start at 50
    line 2: lives = lives * 2; // double it
    line 3: lives = lives + 2; // double it
    line 4: show(lives); // show it
    (a) line 3 (b) line 2 (c) line 1
  24. 24.🐞 A comment in code (after //) is for ___. (a) the battery (b) the app store (c) the phone screen (d) people reading the code
  25. 25.🐞 Each comment says what its line SHOULD do. Which line has the bug?
    line 1: let coins = 30; // start at 30
    line 2: coins = coins - 3; // take away 3
    line 3: coins = coins + 3; // add 3
    line 4: coins = coins - 8; // take away 5
    line 5: show(coins); // show it
    (a) line 2 (b) line 4 (c) line 1 (d) line 3
  26. 26.🐞 This code has a bug. What number SHOULD it show, if every line did what its comment says?
    line 1: let lives = 39; // start at 39
    line 2: lives = lives * 2; // double it
    line 3: lives = lives * 3; // double it
    line 4: lives = lives - 2; // take away 2
    line 5: show(lives); // show it
  27. 27.🐞 This code has a bug. What number SHOULD it show, if every line did what its comment says?
    line 1: let points = 50; // start at 50
    line 2: points = points + 2; // take away 2
    line 3: points = points * 2; // double it
    line 4: show(points); // show it
  28. 28.🐞 This code has a bug. What number does it ACTUALLY show?
    line 1: let coins = 47; // start at 46
    line 2: coins = coins * 2; // double it
    line 3: coins = coins + 2; // add 2
    line 4: coins = coins + 6; // add 6
    line 5: show(coins); // show it
  29. 29.🐞 This code has a bug. What number SHOULD it show, if every line did what its comment says?
    line 1: let coins = 46; // start at 46
    line 2: coins = coins - 5; // take away 3
    line 3: coins = coins - 2; // take away 2
    line 4: coins = coins + 3; // add 3
    line 5: show(coins); // show it
  30. 30.🐞 This code has a bug. What number does it ACTUALLY show?
    line 1: let coins = 50; // start at 50
    line 2: coins = coins + 2; // double it
    line 3: coins = coins + 2; // add 2
    line 4: coins = coins - 1; // take away 1
    line 5: show(coins); // show it
  31. 31.🐞 Each comment says what its line SHOULD do. Which line has the bug?
    line 1: let score = 48; // start at 48
    line 2: score = score * 2; // double it
    line 3: score = score * 3; // double it
    line 4: show(score); // show it
    (a) line 2 (b) line 1 (c) line 3
  32. 32.🐞 Each comment says what its line SHOULD do. Which line has the bug?
    line 1: let coins = 32; // start at 32
    line 2: coins = coins * 2; // double it
    line 3: coins = coins + 6; // add 6
    line 4: coins = coins + 3; // take away 3
    line 5: show(coins); // show it
    (a) line 2 (b) line 4 (c) line 3 (d) line 1
  33. 33.🐞 Each comment says what its line SHOULD do. Which line has the bug?
    line 1: let score = 45; // start at 45
    line 2: score = score + 2; // take away 2
    line 3: score = score - 5; // take away 5
    line 4: show(score); // show it
    (a) line 3 (b) line 2 (c) line 1
  34. 34.🐞 Each comment says what its line SHOULD do. Which line has the bug?
    line 1: let stars = 31; // start at 31
    line 2: stars = stars + 4; // take away 4
    line 3: stars = stars + 6; // add 6
    line 4: stars = stars * 2; // double it
    line 5: show(stars); // show it
    (a) line 1 (b) line 2 (c) line 4 (d) line 3
  35. 35.🐞 This code has a bug. What number SHOULD it show, if every line did what its comment says?
    line 1: let points = 35; // start at 35
    line 2: points = points + 3; // add 3
    line 3: points = points - 4; // take away 4
    line 4: points = points + 5; // take away 5
    line 5: show(points); // show it
  36. 36.🐞 Each comment says what its line SHOULD do. Which line has the bug?
    line 1: let coins = 32; // start at 32
    line 2: coins = coins - 5; // take away 4
    line 3: coins = coins + 3; // add 3
    line 4: coins = coins + 4; // add 4
    line 5: show(coins); // show it
    (a) line 2 (b) line 4 (c) line 1 (d) line 3
  37. 37.🐞 This code has a bug. What number SHOULD it show, if every line did what its comment says?
    line 1: let score = 40; // start at 38
    line 2: score = score - 1; // take away 1
    line 3: score = score - 2; // take away 2
    line 4: show(score); // show it
  38. 38.🐞 Each comment says what its line SHOULD do. Which line has the bug?
    line 1: let coins = 40; // start at 40
    line 2: coins = coins + 1; // take away 1
    line 3: coins = coins - 5; // take away 5
    line 4: show(coins); // show it
    (a) line 3 (b) line 2 (c) line 1
  39. 39.🐞 This code has a bug. What number does it ACTUALLY show?
    line 1: let coins = 53; // start at 50
    line 2: coins = coins * 2; // double it
    line 3: coins = coins + 4; // add 4
    line 4: show(coins); // show it
  40. 40.🐞 This code has a bug. What number SHOULD it show, if every line did what its comment says?
    line 1: let coins = 32; // start at 31
    line 2: coins = coins - 1; // take away 1
    line 3: coins = coins - 1; // take away 1
    line 4: show(coins); // show it

Answer key

  1. find where it goes wrong
  2. 127
  3. line 2
  4. line 2
  5. 43
  6. debugging
  7. line 3
  8. line 2
  9. 44
  10. 232
  11. test it again
  12. 88
  13. 48
  14. line 1
  15. 29
  16. 136
  17. a mistake in the code
  18. 94
  19. 40
  20. 35
  21. 53
  22. 70
  23. line 3
  24. people reading the code
  25. line 4
  26. 154
  27. 96
  28. 102
  29. 44
  30. 53
  31. line 3
  32. line 4
  33. line 2
  34. line 2
  35. 29
  36. line 2
  37. 35
  38. line 2
  39. 110
  40. 29

Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students