I don’t have much to talk about today.
Javascript is getting more challenging, but I think I can do this. I have my notes here.
Tommy and I are going to Portales to see Alexis at her concert tomorrow. She and her friends are going to the college prom tonight. I expect to see pictures tomorrow, if not tonight.
Today I did coding, went dinner shopping, and listened to Karissa and Kel banter for about 20 minutes.
I’m feeling a bit better about Lexi’s internship for this summer. I have the address to where she will be staying and the number of the housing director and also the address of where she will be working. Part of me just wants to keep her in a little box where I know she will be safe. But I do have to let her live her life. This is a great opportunity for her.
I keep zoning out. And my mouse is driving me insane. I need to get dinner going soon, and pack tonight.
——————————————————————
If you need to match one value against many options, you can use a switch statement. A switch statement compares the value to the case statements which define various possible values. Any valid JavaScript statements can be executed inside a case block and will run from the first matched case value until a break is encountered.
switch (fruit) { case "apple": console.log("The fruit is an apple"); break; case "orange": console.log("The fruit is an orange"); break; }
In a switch statement you may not be able to specify all possible values as case statements. Instead, you can add the default statement which will be executed if no matching case statements are found. Think of it like the final else statement in an if/else chain.
switch (num) { case value1: statement1; break; case value2: statement2; break; ... default: defaultStatement; break; }
If the break statement is omitted from a switch statement’s case, the following case statement(s) are executed until a break is encountered. If you have multiple inputs with the same output, you can represent them in a switch statement like this:
let result = ""; switch (val) { case 1: case 2: case 3: result = "1, 2, or 3"; break; case 4: result = "4 alone"; }
If you have many options to choose from, a switch statement can be easier to write than many chained if/else if statements. The following:
if (val === 1) { answer = "a"; } else if (val === 2) { answer = "b"; } else { answer = "c"; }
can be replaced with:
switch (val) { case 1: answer = "a"; break; case 2: answer = "b"; break; default: answer = "c"; }
When a return statement is reached, the execution of the current function stops and control returns to the calling location.
function myFun() { console.log("Hello"); return "World"; console.log("byebye") } myFun();