5. Logical Operators


I have no idea what I am doing, lol.

    var user = prompt("You find yourself waking up in the middle of Calculus class. Do you listen, run, or restroom?").toUpperCase();
    var random = (Math.floor(Math.random()) * 2)

    switch (user) {
        case 0 'LISTEN':
            if (case 0 && random===1){
                console.log("You end up spending your time in class and writing what is remaining of the notes.")
                console.log("You sit there frustrated that you are wasting your time.")
        case 1 'RUN':
            if (case 1 || random===1){
                console.log("The professor scratches your name off the participation list for this day. You also miss an answer to an extra credit question on the upcoming test!")
                console.log("You walk out and the professor still doesn't really even gives a shit!")
        case 2 'RESTROOM':
            if (case 2 && random===1){
                console.log("The professor does nothing to adversely affect your grade. However you miss an answer to an extra credit question on the upcoming test!")
                console.log("The professor makes a joke of you while you are gone and you are shunned for the rest of your college career!")
            console.log("What the heck is " + user + "? Idiot!")




switch (parameter-expression) {
  case value1:
    //Statements executed 
    //      when the VALUE of expression matches value1
  case value2:
     //Statements executed 
    //      when the VALUE of expression matches value2
  case valueN:
    //Statements executed 
    //      when the VALUE of expression matches valueN
    //Statements executed 
    //      when none of the VALUE's match the VALUE of the expression

= = = = = = = = = = = = = = = = = = = = = = = = = = = =

The switch statement evaluates an parameter-expression,
matching the parameter-expression's VALUE to a case clause,
and executes statements associated with that case.
( and with the break or return-statement will exit the switch statement )

= = = = = = = = = = = = = = = = = = = = = = = = = = = =

In your case clause you are using an expression
An expression is any valid unit of code that resolves to a VALUE.

Conceptually, there are two types of expressions:
-1 those that assign a value to a variable
2- those that simply resolve to a VALUE.

So in your case clause you are using the 2nd kind of expression
and you do that by
using the variable user =comparing= it to the string Value 'LISTEN'
which will result in a Boolean VALUE

Thus your case clause VALUE 'LISTEN'
is matched against the VALUE of the parameter-expression


A Math.random()
will return a number Value between 0.000 =and= 0.9999 ( thus 1 is EXCLUDED )

Also follow the link logical operators


@hackintoshftw1: Tananan... lol, I like your case study. But we use case so that we do not need to use if/else a lot.


Sometimes it's better to use neither. For example, in a "dispatch" situation, Javascript lets you do things in a completely different way:
and read
The performance difference between a switch and if...else if...else is small, they basically do the same work. One difference between them that may make a difference is that the expression to test is only evaluated once in a switch while it's evaluated for each if. If it's costly to evaluate the expression, doing it one time is of course faster than doing it a hundred times


I did not think of the performance and I did not have any idea of "Dispatch Situation". But, of course it is good to know and thanks for letting me know. I will have a look.

I saw a bench mark test in Ruby section in Codecademy where they demonstrated why it is good to use symbol for performance. But that's a different topic but gave me a quick idea that we do programming for software performance too.I was thinking to learn more about performance. In the meantime, I will see your link. Thanks again.


Thanks for the reply.

Actually I do know what I am doing, but IDK why it gives me a syntax error. It says,

SyntaxError: Unexpected string


You will have to change the CASE-clause

case 'LISTEN':



Thats. Strange! Since if you look at the "Hint" that they gave me, this is the example that they gave...

switch(month) {

    case 0:

        if(day == 1) {
            console.log("Happy New Year");
        else {
            console.log("Happy January");


    /* ... */


Also, I removed the 0,1,2, etc. Still gives a syntax error...

SyntaxError: Unexpected token case


I the example as mentioned inyour prior post
the switch is comparing =month= with the number Value 0

So going back to your Original Post
where you used a CASE clause
case 0 'LISTEN':
This is NOT possible.....
you either use
case 0:
case 'LISTEN':

I hope you are aware that a prompt() statement will return a string Value


google search
== the Book ==
javascript [your question] site:developer.mozilla.org

== discussions / opinions ==
javascript [your question] site:stackoverflow.com

== guidance ==
http://javascript.crockford.com/code.html <---JavaScript code-convention