SPM Trial Revision 2026

Sains Komputer Form 5 Trial Tips

Your interactive revision portal for the upcoming Sains Komputer trials. We've compiled textbook diagrams directly from chapters covering algorithms, standard libraries, client-side scripting (JavaScript), procedures/functions, and memory visualization.

01

Finding the Maximum Value

Proses Mencari Nilai Maksimum (Rajah 3.1.28)

Proses mencari nilai maksimum textbook diagram
Click to enlarge (Rajah 3.1.28)

This diagram outlines the logical sequence for finding the maximum value within a collection of items (such as an array):

  • Beri nilai awal maksimum (Initialize Max Value): Assign the first element of the array or a very small default number as the initial maximum.
  • Banding nilai dalam senarai (Compare with current items): Loop through the remaining elements and compare each item against the current maximum value.
  • Dapat nilai maksimum terkini (Update new maximum): If a compared element is larger than the stored maximum, update the stored value with the new maximum. Repeat until all elements have been evaluated.
02

Introduction to Standard Libraries

Kelebihan & Pengenalan Standard Library (Bahagian 3.1.5)

Pengenalan standard library textbook page
Click to enlarge (Halaman 194)

A Standard Library (Perpustakaan Standard) is a collection of built-in methods and functions supplied by the programming language specification to assist programmers in coding common operations.

  • Efficiency: Saves development time by providing pre-built functions for data structures, algorithms, math operations, and input/output mechanisms.
  • Common JavaScript Standard Libraries in the Textbook:
    • math.js: Used for mathematical formulas like math.sqrt() (square root) and math.pow() (exponents).
    • date.js: Used for date tracking functions such as date.now() and formatting.
03

Fungsi math.js (Mathematical Library Methods)

Jadual 3.1.30 Fungsi-fungsi dalam math.js

Fungsi-fungsi dalam math.js textbook list
Click to enlarge (Jadual 3.1.30)

The textbook specifies five core operations within the math.js standard library that you should memorize for paper questions:

Fungsi (Method Call) Penerangan (English Translation)
math.add(x, y) Menambah dua nombor (Adds two numbers)
math.divide(x, y) Membahagi dua nombor (Divides x by y)
math.subtract(x, y) Menolak dua nombor (Subtracts y from x)
math.pow(x, y) Mengira kuasa kepada nombor (Raises x to the power of y)
math.sqrt(x) Mengira punca kuasa bagi nombor (Calculates square root of x)
04

Modular Programming & Sub-routines

Rajah 3.1.44 Modul Utama dan Subatur Cara

Modul utama yang dipecahkan textbook diagram
Click to enlarge (Rajah 3.1.44)

Modular programming divides a single script into smaller, isolated components. In client-side scripting, this is achieved using subatur cara (sub-routines).

  • Modul Utama (Main Module): Represents the main script flow which invokes helper modular blocks.
  • Sub-routine Categories:
    • Prosedur (Procedure): A block of code designed to perform a task but does not return a value back to the caller.
    • Fungsi (Function): Performs operations and returns a value back to the caller using a return statement.
05

Procedures vs Functions

Perbezaan antara Prosedur dengan Fungsi (Jadual 3.1.35)

Perbandingan prosedur dan fungsi textbook comparison
Click to enlarge (Jadual 3.1.35)

Understanding when to use a Procedure vs a Function is a guaranteed scoring topic. Here is the formal breakdown:

Aspek Prosedur (Procedure) Fungsi (Function)
Memulangkan Nilai Tidak memulangkan nilai Memulangkan nilai
Contoh Panggilan toCelcius(fahrenheit); celcius = toCelcius(fahrenheit);

Textbook Typo Alert: Under "Contoh definisi" for Fungsi in Jadual 3.1.35, the code has: celcius = (5/9) * fahrenheit - 32);. Note the trailing closing parenthesis. Avoid copying this syntax typo in your theory papers; it will lead to runtime syntax errors in actual code!

06

Array Declaration & Manual Retrieval

Mengisytiharkan Array & Akses Satu per Satu (ms206(a))

Mendapatkan nombor dalam senarai satu per satu textbook page
Click to enlarge (Jadual 3.1.39(a))

For ms206(a), the textbook demonstrates retrieving elements one by one manually using indices to sum up numbers. You must know how arrays are declared and written in both JavaScript and Java, and understand their core differences.

javascript // Declaring and initializing array in JavaScript var no = [5, -1, 4, 12, 8]; var jumlah = 0; // Adding values manually element-by-element jumlah = no[0] + no[1] + no[2] + no[3] + no[4]; document.write(jumlah); // Outputs: 28
java // Declaring and initializing array in Java (Fixed data types) int[] no = {5, -1, 4, 12, 8}; int jumlah = 0; // Adding values manually element-by-element jumlah = no[0] + no[1] + no[2] + no[3] + no[4]; System.out.println(jumlah); // Outputs: 28
Feature JavaScript Array Java Array
Type System Dynamic typing (can hold multiple types: strings, numbers, etc.) Static typing (must declare type e.g., int[], homogeneous elements)
Declaration Syntax var no = [5, -1, 4, 12, 8]; int[] no = {5, -1, 4, 12, 8};
Size Constraint Dynamic size (can grow/shrink) Fixed size (once declared, the size cannot be changed)
07

Loops and Memory Blocks

Menggunakan Ulangan untuk Menjumlahkan Senarai (ms206(b))

Menggunakan ulangan untuk mendapatkan nombor textbook page
Click to enlarge (Jadual 3.1.39(b))

For ms206(b), you must know how to change loops from for to while, while to for, or do-while. Additionally, you are required to know how to draw a Blok Memori (Block Memory) diagram for arrays.

Loop Conversion Playground

Select a language and loop type to view side-by-side structures:

javascript var no = [5, -1, 4, 12, 8]; var jumlah = 0; var i; for (i = 0; i < 5; i++) { jumlah = jumlah + no[i]; } document.write(jumlah);
javascript var no = [5, -1, 4, 12, 8]; var jumlah = 0; var i = 0; // Initialize control variable while (i < 5) { // Loop condition jumlah = jumlah + no[i]; i++; // Increment variable } document.write(jumlah);
javascript var no = [5, -1, 4, 12, 8]; var jumlah = 0; var i = 0; // Initialize control variable do { jumlah = jumlah + no[i]; i++; // Increment variable } while (i < 5); // Loop condition (executes at least once) document.write(jumlah);
java int[] no = {5, -1, 4, 12, 8}; int jumlah = 0; for (int i = 0; i < 5; i++) { jumlah = jumlah + no[i]; } System.out.println(jumlah);
java int[] no = {5, -1, 4, 12, 8}; int jumlah = 0; int i = 0; // Initialize control variable while (i < 5) { // Loop condition jumlah = jumlah + no[i]; i++; // Increment variable } System.out.println(jumlah);
java int[] no = {5, -1, 4, 12, 8}; int jumlah = 0; int i = 0; // Initialize control variable do { jumlah = jumlah + no[i]; i++; // Increment variable } while (i < 5); // Loop condition System.out.println(jumlah);

Interactive Block Memory Visualizer (Blok Memori)

In SPM exams, you must draw array memory as contiguous boxes. Hover/click cell nodes to view index accesses:

no[0] 5 0x7FFF1000
no[1] -1 0x7FFF1004
no[2] 4 0x7FFF1008
no[3] 12 0x7FFF100C
no[4] 8 0x7FFF1010
> Click on a block memory cell above to trace.