Skip to content
SPM Tuition
Practice · Computer Science

Web development practice with explained answers

You have worked through the lessons and want questions that show whether the ideas stuck.

These seven original questions follow one path: input box, processing, validation, keyboard use and the test log. They belong to web development without assessed-project substitution. Attempt each on paper first.

Questions

Question 1

Two boxes hold “25” and “5”. The code reads both values and shows a + b. What appears, and why?

Answer

The page shows 255. Box values are text, so + joins “25” and “5” into “255”. To get 30, convert each value with Number() before adding.

See tracing data from an HTML input to a displayed classroom result.

Question 2

Complete the trace for a box holding “80”, where the code is var m = Number(box.value); if (m >= 50) show "Pass".

Answer
  1. box.value is “80” (text).
  2. m = 80 (number).
  3. 80 >= 50 is true.
  4. The page shows “Pass”.

Question 3

What does an empty box give when read, and what does Number() turn it into? Why is that a problem for a mark checker?

Answer

An empty box gives the empty text “”, and Number(“”) is 0. A blank entry would then be treated as a mark of 0 and shown as a fail, when the user actually entered nothing. The page should check for an empty box first and ask for a mark.

Question 4

A page shows “Enter a mark from 0 to 100” using JavaScript, and the server has no check. A user sends the mark 250 without using the page. What happens, and what should change?

Answer

The browser check is skipped, and the server has no check, so 250 is accepted and stored. The server must validate the range itself. The browser message can stay, since it gives honest users quick feedback.

Question 5

Name one check that only the server can perform for a sign-up form, and explain why the browser cannot.

Answer

Checking whether a username is already taken. The list of existing usernames is stored on the server, so the browser has no way to compare against it. The lesson on client-side feedback versus server-side validation gives the full comparison.

Question 6

During a keyboard-only test, pressing Tab skips the Send button, which is built as a div with a click handler. Explain the fault and the fix.

Answer

A plain div is not an interactive control, so Tab does not reach it and Enter does not activate it. Replace it with a button element and keep the existing click handler. Then repeat the Tab and Enter steps. See testing a small page with keyboard-only interaction.

Question 7

Rewrite this test log row so it is reproducible: “Tried a big number. Got an error. Fixed it.”

Answer

One version:

  • T4. Start: fresh page load, Mark box empty.
  • Steps: type 250 in the Mark box, click Check once.
  • Expected: message ‘Mark must be 0 to 100’.
  • Actual: page showed Pass. Result: fail.
  • Change: added a check that rejects marks above 100.
  • Re-test actual: message shown. Result: pass.

It fixes the start state, the input, the steps, the expected and actual results, and the change. Compare it with documenting student-authored changes with a reproducible test log.

If you got these wrong

  • Questions 1 to 3: read the tracing lesson linked under question 1.
  • Questions 4 and 5: read the validation lesson linked under question 5.
  • Question 6: read the keyboard lesson linked under question 6.
  • Question 7: read the test log lesson linked under question 7.

To go through your answers with a teacher, see online one-to-one Computer Science tuition.

Common questions

Are these real SPM questions?

No. They are original practice questions written to train the skills in this cluster. Use them to check your understanding, and use your school's official materials for past-paper style practice.

How do I get the most from them?

Write your answer on paper first, including any trace table. Then compare with the worked answer and mark the step where you differed, because that step is what to practise.

Can I do them in a different order?

Yes, but the order follows how data moves through a page, so the early questions help with the later ones. If you skip, still attempt the trace in question 1.

If a question type keeps going wrong, a teacher in one-to-one Computer Science lessons can look at how you reasoned and correct the step that slips, using further practice pages.

  • Online one-to-one lessons for your child with an experienced teacher.
  • Your first class is a one-hour trial, from RM50. The fee is agreed before you book.
  • Happy with the teacher? Continue with lessons of about 1.5 hours. If not, ask for another teacher.