Assignment 4 | Carson Alonzo

Option A: buttons Note: If you want to learn anything, avoid using an AI for this problem unless you get completely stuck and really need a hint.

A1. Conditionals.

  1. Declare and assign a value to x. If x is 3, print "x === 3". Add an else clause. It prints "x===4". Alas, your program has a bug: if x is 5 it still prints "x === 4"!

    let text = "";
    let x = 5;

    Incorrect conditional construct

    if (x === 3) {
         text = "x = 3";
    }
    else {
         text = "x = 4";
    }

    This prints:

  2. Fix the bug with an "else if" construct, so that now, if x is 4 it correctly prints "x===4" but on the other hand if x is not 4 it correctly prints "x != 4".

    let text = "";
    let x = 5;

    Correct conditional construct

    if (x === 3) {
         text = "x = 3";
    }
    elseif (x === 4) {
         text = "x = 4";
    }
    else{
         text = "x != 4";
    }

    This prints:

  3. A2. More conditionals.
    1. Demonstrate the if statement using a button.
    2. Demonstrate the if else statement using a button.
    3. Demonstrate the "else if" statement (an if else statement in which the else clause is another if else statement) using a button.

    A3. Implement a for loop, a while loop, and a do while loop. These should involve buttons that demonstrate the loops.

    A4. Modify the button styles. Here is an example: (check the source code for this button to see how it is done).