Sonzaschool
Back

O-Level · Form 2 · Vocational · Electronics and Computer

Computer Programming

Implementing selection, loop, and array

about 4 minutes to read

Discussions
Topics in this sectionImplementing web scripting4 topics

Selection, loops, and arrays are three fundamental building blocks that allow a program to make decisions, repeat actions, and store collections of data.

Selection statements let the program choose different actions based on conditions. The main types are if, else, and switch.

The if Statement

The if statement checks a condition. If the condition is true, the code inside the block runs.

let score = 75;
if (score >= 50) {
    console.log("You passed!");
}

The if-else Statement

When you want one action if the condition is true and a different action if it is false, use else.

let temperature = 30;
if (temperature > 35) {
    console.log("It is very hot today.");
} else {
    console.log("The weather is okay.");
}

The switch Statement

When you have many conditions to check against one value, switch is often clearer than many if statements.

let day = 2;
switch (day) {
    case 1:
        console.log("Monday");
        break;
    case 2:
        console.log("Tuesday");
        break;
    case 3:
        console.log("Wednesday");
        break;
    default:
        console.log("Invalid day");
}

How you'll be assessedProcess assessment · Outcome assessment · Knowledge assessment

Process assessment

  • Apply conditional statements (if-else, switch).
  • Use loops (for, while, do-while).
  • Declare and manipulate arrays.

Outcome assessment

Selection, loop and array are correctly implemented in scripts to perform the required tasks.

Knowledge assessment

Detailed knowledge of:

Method used: The student should explain how to:

  • implement conditions, loops, and arrays.

Principles: The student should explain the principle of:

  • control flow and iteration.

Theories: The student should explain:

  • The concepts of flow control and arrays
  • use of arrays in storing and accessing data. Circumstantial knowledge:

Detailed knowledge about:

  • array methods

Question

What is the index of the first element in a JavaScript array?

Sign in to submit your answer and have it count toward your mastery.

Sign in to practice

Tutor

Stuck? Ask me anything about this topic.

Sign in to ask the Sonza AI Tutor about this question.

Sign in to ask

Discussions

No questions yet

Sign in to ask
Loading discussions…