HW for Units 3.5, 3.6, and 3.7
Boolean & Conditionals Problems
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")
}
}
}
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")
}
}
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