switch/case

Wow, what a crazy new syntax, switch. It seems like it is some kind of deeply embedded object in javascript itself – I have no analogues mentally for it. Before I try to explain myself into an incorrect hole (now there’s a strange metaphor..), I will just go ahead and junk out the syntax so I’ve got a record of it.

var varName = prompt("you have a choice of several things here.")

switch(varName) {
    case "first choice":
        // here is where stuff happens as a result of the first choice!
    case "second choice":
        // aaannnnd second choice
    default:
        // everything else goes here if the other cases do not happen

I will poke at this and try to see how to manipulate this in different-than-standard ways. Does it need to be a prompt? I bet it can take an element of a random array. Moving on!

Advertisements