My computer mouse is driving me insane. It keeps turning off, and I have to wriggle the cable attached so it will turn on again. But that only lasts seconds to a few minutes.
I was leaving to go to the post office earlier and saw a package by the gate. They dropped off the package at the wrong address. I was going to the post office anyway, so I took it with me. When I got to the post office, I didn’t realize that the box said UPS. So I had to take it up the street to drop off the package. I did some coding today. Which was good, but my mouse was making it a bit hard.
Tommy and I stayed up until 2 am talking Friday night, so I woke up on Saturday around 12. We have talked about things that happened in the past. I’m still feeling raw from it. I haven’t even talked to my therapist, my old therapist, about it. I wasn’t feeling very comfortable talking about it with my old therapist. I feel myself dissociating right now as I type. It’s getting harder to think.
Next Saturday, Alexis has her concert. Tommy and I will be traveling up to see her. I’m told to bring her some totes, so I assume she is already beginning to pack for the summer. She will be done with the semester in mid-May. I believe Karissa will be done during the same time.
I’m going to get back to coding. These are my notes so far from Friday and today.
—————————————————
A function can include the return statement but it does not have to. In the case that the function doesn’t have a return statement, when you call it, the function processes the inner code but the returned value is undefined.
let sum = 0; function addSum(num) { sum = sum + num; } addSum(3);
If you’ll recall from our discussion about Storing Values with the Assignment Operator, everything to the right of the equal sign is resolved before the value is assigned. This means we can take the return value of a function and assign it to a variable.
ourSum = sum(5, 12);
In Computer Science a queue is an abstract Data Structure where items are kept in order. New items can be added at the back of the queue and old items are taken off from the front of the queue.
Another data type is the Boolean. Booleans may only be one of two values: true or false. They are basically little on-off switches, where true is on and false is off. These two states are mutually exclusive.
Note: Boolean values are never written with quotes. The strings “true” and “false” are not Boolean and have no special meaning in JavaScript.
if statements are used to make decisions in code. The keyword if tells JavaScript to execute the code in the curly braces under certain conditions, defined in the parentheses. These conditions are known as Boolean conditions and they may only be true or false.
When the condition evaluates to true, the program executes the statement inside the curly braces. When the Boolean condition evaluates to false, the statement inside the curly braces will not execute.
if (condition is true) {
statement is executed
}
function test (myCondition) { if (myCondition) { return "It was true"; } return "It was false"; } test(true); test(false);
There are many comparison operators in JavaScript. All of these operators return a boolean true or false value.
The most basic operator is the equality operator ==. The equality operator compares two values and returns true if they’re equivalent or false if they are not. Note that equality is different from assignment (=), which assigns the value on the right of the operator to a variable on the left.
function equalityTest(myVal) { if (myVal == 10) { return ""; } return "Not Equal"; }
If myVal is equal to 10, the equality operator returns true, so the code in the curly braces will execute, and the function will return Equal. Otherwise, the function will return Not Equal. In order for JavaScript to compare two different data types (for example, numbers and strings), it must convert one type to another. This is known as Type Coercion. Once it does, however, it can compare terms as follows:
1 == 1 // true 1 == 2 // false 1 == '1' // true "3" == 3 // true
Strict equality (===) is the counterpart to the equality operator (==). However, unlike the equality operator, which attempts to convert both values being compared to a common type, the strict equality operator does not perform a type conversion.
3 === 3 // true 3 === '3' // false
In the last two challenges, we learned about the equality operator (==) and the strict equality operator (===). Let’s do a quick review and practice using these operators some more.
If the values being compared are not of the same type, the equality operator will perform a type conversion, and then evaluate the values. However, the strict equality operator will compare both the data type and value as-is, without converting one type to the other.
typeof 3 typeof '3'
typeof 3 returns the string number, and typeof ‘3’ returns the string string.
The inequality operator (!=) is the opposite of the equality operator. It means not equal and returns false where equality would return true and vice versa. Like the equality operator, the inequality operator will convert data types of values while comparing.
1 != 2 // true 1 != "1" // false 1 != '1' // false 1 != true // false 0 != false // false
The strict inequality operator (!==) is the logical opposite of the strict equality operator. It means “Strictly Not Equal” and returns false where strict equality would return true and vice versa. The strict inequality operator will not convert data types.
3 !== 3 // false 3 !== '3' // true 4 !== 3 // true
The greater than operator (>) compares the values of two numbers. If the number to the left is greater than the number to the right, it returns true. Otherwise, it returns false.
5 > 3 // true 7 > '3' // true 2 > 3 // false '1' > 9 // false
The greater than or equal to operator (>=) compares the values of two numbers. If the number to the left is greater than or equal to the number to the right, it returns true. Otherwise, it returns false.
Like the equality operator, the greater than or equal to operator will convert data types while comparing.
6 >= 6 // true 7 >= '3' // true 2 >= 3 // false '7' >= 9 // false
The less than operator (<) compares the values of two numbers. If the number to the left is less than the number to the right, it returns true. Otherwise, it returns false. Like the equality operator, the less than operator converts data types while comparing.
2 < 5 // true '3' < 7 // true 5 < 5 // false 3 < 2 // false '8' < 4 // false
The less than or equal to operator (<=) compares the values of two numbers. If the number to the left is less than or equal to the number to the right, it returns true. If the number on the left is greater than the number on the right, it returns false. Like the equality operator, the less than or equal to operator converts data types.
4 <= 5 // true '7' <= 7 // true 5 <= 5 // true 3 <= 2 // false '8' <= 4 // false
Sometimes you will need to test more than one thing at a time. The logical and operator (&&) returns true if and only if the operands to the left and right of it are true.
if (num > 5 && num < 10) { return "Yes"; } return "No";