6/6 Control flow


#1

https://www.codecademy.com/en/courses/javascript-beginner-en-ZA2rb/0/6?curriculum_id=506324b3a7dffd00020bf661


var user = prompt("Would you vote for Bernie Sanders? Lets test your poltical beliefs! Remember to type in: start quiz").toLowerCase();

switch(user) {
    case 'start quiz':
        var type1 = prompt("Do you agree: Humans are rational beings who act in their own self-interest");
    var type2 = prompt("Do you agree: Humans are social creatures thrive on solidarity");
    var type3 = prompt("Do you agree: Government regulation of business is necessary to protect the public interest");
    var type4 = prompt("Do you agree: Government regulation of business usually does more harm than good");
    var type5 = prompt("Do you agree: Universal healthcare is a human right");
    if (type1 === 'yes' || type2 === 'no' || type3 === 'yes' || type4 === 'yes' || type5 === 'no') {
        console.log("You are a liberal and probably shouldn't vote for Bernie Sanders"); } 
        else if (type1 === 'no' || type2 === 'yes' || type3 === 'no' || type4 === 'no' || type5 === 'no') {
    console.log("You are a conservative");
    } else {
        console.log("You are a real socialist!");
    }
    if (type1 === "no" && type2 === "no") {
        console.log("That doesn't really seem to make any sense! Let's try again");
    }
};


#2

@mads_genefke

Remember to put a break; after each of your case


#3

Everything works except the last else statement. If type like "no, no, no, no, no, no" it says "You are a liberal", but if i just type in things like "■■■■, die, lol, wut, hi, wassup" it says "You are a conservative"

var user = prompt("Political Typology Quiz").toLowerCase();

switch(user) {
case 'start quiz':
var type1 = prompt("Do you agree: Humans, are by nature, rational beings who act in their own self-interest");
var type2 = prompt("Do you agree: Humans, are by nature, social creatures that thrive when they work together");
var type3 = prompt("Do you agree: We shouldn't punish succesful and rich people therefore everyone should pay the same precentage in income tax");
var type4 = prompt("Do you agree: Succesful and rich people are morally obliged to help those in need and therefore should pay more in tax");
var type5 = prompt("Do you agree: Government regulation of business is necessary to protect public interest");
var type6 = prompt("Do you agree: Government regulation of business usually does more harm than good");
if ((type1 === 'yes') || type2 === 'no' || type3 === 'yes' || type4 === 'no' || type5 === 'no' || type6 === 'yes') {
console.log("You are a liberal");
} else if (type1 === "no" || type2 === "yes" || type3 === "no" || type4 === "yes" || type5 === "yes" || type6 === "no") {
console.log("You are a socialist");
} else {
console.log("You are a conservative");
}
break;
}


#4

@mads_genefke

This is because what you type does not fill in the conditions in the if and else if statement. Here, they are testing about if your answer is yes or no but you just typed something else so it went to the else statement to execute the code.