Nested Code Activity

hours = 11

if (hours < 8)
{
    console.log ("This person is unexperienced, salary is 50k!")
}
else
{
    if (hours < 10)
    {
    console.log ("This person's salary is 90k, and they are experienced")
    }
    else 
    {
    if (hours >= 10)
    {
    console.log ("This person's salary is 150k, and they are experienced")
    }
}
}
This person's salary is 150k, and they are experienced

Conditionals

product = {"expired":false, "cost":10}

if (product["expired"] == true) {
    console.log("this product is no good")
}
else {
    if (product["cost"] > 50) {
        console.log("this product is too expensive")
    }
    else if (product["cost"] > 25) {
        console.log("this is a regular product")
    }
    else {
        console.log("this is a cheap product")
    }
}
this is a cheap product

Multiple Choice Activity

qAndA = {
    "question" : ["Who was the leader of the Stalwarts?", "What is the capital of Canada", "What country is winning the world cup this year?"],
    "answers" : [["Roscoe Conkling","James A. Garfield","James Blaine","Chester A. Arthur"], ["Otawa","Ottawa","Otawwa","Otowa"], ["France","Brazil","England","Argentina"]], 
    "correct" : ["a", "b", "d"],
    "letters" : ["a", "b", "c", "d"]
    }

totalQs = len(qAndA["question"])
i = 0
score = 0

while i != totalQs:
    qAnswered = False

    currentQ = qAndA["question"][i]
    print(currentQ + "\n")
    
    n = 0

    while n < 4:
        print(str(qAndA["letters"][n]) + ": " + str(qAndA["answers"][i][n]))
        n += 1
    
    ans = input(currentQ)
    ans.lower()
    
    print("")
    
    while qAnswered == False:
        if  ans == "a" or "b" or "c" or "d":
            if ans == qAndA["correct"][i]:
                score += 1
                print("correct")
            else:
                print("incorrect :(")

            qAnswered = True
        else:
            print("Enter a valid letter option (a, b, c, or d)")
            
    print("you score is: " + str(score) + "\n")
    
    i += 1
Who was the leader of the Stalwarts?

a: Roscoe Conkling
b: James A. Garfield
c: James Blaine
d: Chester A. Arthur

correct
you score is: 1

What is the capital of Canada

a: Otawa
b: Ottawa
c: Otawwa
d: Otowa

correct
you score is: 2

What country is winning the world cup this year?

a: France
b: Brazil
c: England
d: Argentina

correct
you score is: 3