{"base":{"id":"cs9-15","subject":"Programming","title":"Debugging with a trace table","scene":"code9","steps":[{"mode":"tracebug","eyebrow":"Something's wrong","title":"Trace and compare","body":"This program should output the average of 6, 9 and 3, which is 6. Step through and fill the trace table. Compare each value of total with what it should be.","actions":[{"id":"step","label":"Step"},{"id":"run","label":"Run"},{"id":"reset","label":"Reset"}]},{"mode":"tracefix","eyebrow":"Fix and retrace","title":"Check every row","body":"Line 4 overwrote total instead of adding to it. With the fix, total builds up 6, 15, 18. Retrace to check every row matches.","actions":[{"id":"step","label":"Step"},{"id":"run","label":"Run"},{"id":"reset","label":"Reset"}]},{"mode":"tracebug","eyebrow":"Practise","title":"Find the first wrong row","body":"Run the buggy version once more. The first row where total differs from the expected value tells you which line to look at.","actions":[{"id":"step","label":"Step"},{"id":"run","label":"Run"},{"id":"reset","label":"Reset"}]},{"mode":"quiz","eyebrow":"Check yourself","title":"Read the trace","body":"A trace table shows total = 5, then 7, then 2. The inputs were 5, 2 and 2, and total should be the running sum.","question":"Where does it first go wrong?","options":["The third row","The first row","The second row"],"answer":0,"right":"Correct. Expected 5, 7, 9: the third row (2) is the first wrong value.","wrong":"Not quite. Compare each row with the expected running total.","look":"tracebug"}],"more":[{"type":"cards","id":"ideas","eyebrow":"Popular idea vs science","title":"Common mix-ups","items":[{"tag":"Popular idea","title":"\"Debugging is guessing until it works.\"","body":"A trace table shows exactly where values go wrong, so you can fix the right line."},{"tag":"Popular idea","title":"\"If the output is wrong, the last line is wrong.\"","body":"The bug is usually earlier; the output only shows the result."},{"tag":"Popular idea","title":"\"Trace tables are only for exams.\"","body":"Programmers use the same idea with debuggers and print statements."}]},{"type":"cards","id":"code","eyebrow":"Pseudocode","title":"The bug","items":[{"tag":"Buggy","title":"Average","body":"total ← 0\nFOR i ← 1 TO 3\n    INPUT x\n    total ← x\nNEXT i\nOUTPUT total ÷ 3","code":true},{"tag":"Fixed","title":"Average","body":"total ← 0\nFOR i ← 1 TO 3\n    INPUT x\n    total ← total + x\nNEXT i\nOUTPUT total ÷ 3","code":true}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Bug hunt","items":[{"title":"Trace a friend's code","time":"20 minutes","need":["Paper","A partner"],"steps":["Write a short loop program with one deliberate bug.","Swap with a partner.","Build a trace table with an 'expected' column.","Find the first row where actual ≠ expected and fix the line."],"why":"Comparing actual and expected values row by row is a reliable way to find logic errors.","safety":"No safety risks."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Six more questions","questions":[{"question":"What is a trace table used for in debugging?","options":["Drawing the screen","Recording values to find where they go wrong","Speeding up code"],"answer":1,"right":"Correct. It shows each step's values.","wrong":"Not quite. Tracking values."},{"question":"Which kind of error does a trace table help find most?","options":["Spelling in comments","Power cuts","Logic errors"],"answer":2,"right":"Correct. The program runs but gives wrong results.","wrong":"Not quite. Wrong answer, no crash."},{"question":"total ← x inside a summing loop causes…","options":["an infinite loop","total to keep only the last value","a syntax error"],"answer":1,"right":"Correct. It overwrites total each pass.","wrong":"Not quite. What does ← do?"},{"question":"What should the 'expected' column contain?","options":["Values worked out by hand","Random numbers","The output only"],"answer":0,"right":"Correct. What should happen.","wrong":"Not quite. What should each value be?"},{"question":"After fixing a bug you should…","options":["delete the trace table","retrace or retest","add more bugs"],"answer":1,"right":"Correct. Check that it now works.","wrong":"Not quite. Did the fix work?"},{"question":"Rows: expected 3, 8, 12; actual 3, 8, 5. First wrong row?","options":["Row 1","Row 2","Row 3"],"answer":2,"right":"Correct. 12 vs 5.","wrong":"Not quite. Compare each row."}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can explain…","items":["how to build a trace table","how to compare actual and expected values","how to find the first incorrect result","how to fix and retrace"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"trace table","meaning":"A table of values at each step of a program."},{"word":"expected value","meaning":"What a variable should be."},{"word":"logic error","meaning":"A mistake that gives wrong results without crashing."},{"word":"debug","meaning":"Find and fix errors."},{"word":"overwrite","meaning":"Replace a variable's value."}]},{"type":"sources","id":"sources","title":"Sources","items":["BBC Bitesize KS3 Computer Science","Raspberry Pi Foundation, Computing curriculum resources"]}]},"overlay":null}