Skip to content

Commit b5c1596

Browse files
Niel-Reitmannsaragibby
authored andcommitted
grammar correction
1 parent a1e9ca3 commit b5c1596

File tree

1 file changed

+44
-42
lines changed

1 file changed

+44
-42
lines changed

2-js-basics/3-making-decisions/README.md

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# JavaScript Basics: Making Decisions
22

33
![JavaScript Basics - Making decisions](../../sketchnotes/webdev101-js-decisions.png)
4+
45
> Sketchnote by [Tomomi Imura](https://twitter.com/girlie_mac)
56
67
## Pre-Lecture Quiz
8+
79
[Pre-lecture quiz](https://ashy-river-0debb7803.1.azurestaticapps.net/quiz/11)
810

911
Making decisions and controlling the order in which your code runs makes your code reusable and robust. This section covers the syntax for controlling data flow in JavaScript and its significance when used with Boolean data types
@@ -13,6 +15,7 @@ Making decisions and controlling the order in which your code runs makes your co
1315
> 🎥 Click the image above for a video about making decisions.
1416
1517
> You can take this lesson on [Microsoft Learn](https://docs.microsoft.com/learn/modules/web-development-101-if-else/?WT.mc_id=academic-77807-sagibbon)!
18+
1619
## A Brief Recap on Booleans
1720

1821
Booleans can be only two values: `true` or `false`. Booleans help make decisions on which lines of code should run when certain conditions are met.
@@ -44,8 +47,8 @@ Operators are used to evaluate conditions by making comparisons that will create
4447
The if statement will run code in between its blocks if the condition is true.
4548

4649
```javascript
47-
if (condition){
48-
//Condition is true. Code in this block will run.
50+
if (condition) {
51+
//Condition is true. Code in this block will run.
4952
}
5053
```
5154

@@ -55,9 +58,9 @@ Logical operators are often used to form the condition.
5558
let currentMoney;
5659
let laptopPrice;
5760

58-
if (currentMoney >= laptopPrice){
59-
//Condition is true. Code in this block will run.
60-
console.log("Getting a new laptop!");
61+
if (currentMoney >= laptopPrice) {
62+
//Condition is true. Code in this block will run.
63+
console.log("Getting a new laptop!");
6164
}
6265
```
6366

@@ -69,33 +72,31 @@ The `else` statement will run the code in between its blocks when the condition
6972
let currentMoney;
7073
let laptopPrice;
7174

72-
if (currentMoney >= laptopPrice){
73-
//Condition is true. Code in this block will run.
74-
console.log("Getting a new laptop!");
75-
}
76-
else{
77-
//Condition is false. Code in this block will run.
78-
console.log("Can't afford a new laptop, yet!");
75+
if (currentMoney >= laptopPrice) {
76+
//Condition is true. Code in this block will run.
77+
console.log("Getting a new laptop!");
78+
} else {
79+
//Condition is false. Code in this block will run.
80+
console.log("Can't afford a new laptop, yet!");
7981
}
8082
```
8183

8284
✅ Test your understanding of this code and the following code by running it in a browser console. Change the values of the currentMoney and laptopPrice variables to change the returned `console.log()`.
8385

84-
8586
## Switch Statement
8687

87-
The `switch` statement is used to perform different actions based on different conditions.Use the `switch` statement to select one of many code blocks to be executed.
88+
The `switch` statement is used to perform different actions based on different conditions. Use the `switch` statement to select one of many code blocks to be executed.
8889

8990
```javascript
90-
switch(expression) {
91+
switch (expression) {
9192
case x:
9293
// code block
9394
break;
9495
case y:
9596
// code block
9697
break;
9798
default:
98-
// code block
99+
// code block
99100
}
100101
```
101102

@@ -104,21 +105,20 @@ switch(expression) {
104105
let a = 2;
105106

106107
switch (a) {
107-
108-
case 1:
109-
a = 'one';
110-
break;
111-
case 2:
112-
a = 'two';
113-
break;
114-
default:
115-
a = 'not found';
116-
break;
108+
case 1:
109+
a = "one";
110+
break;
111+
case 2:
112+
a = "two";
113+
break;
114+
default:
115+
a = "not found";
116+
break;
117117
}
118118
console.log(`The value is ${a}`);
119119
```
120-
✅ Test your understanding of this code and the following code by running it in a browser console. Change the values of the varaiable a to change the returned `console.log()`.
121120

121+
✅ Test your understanding of this code and the following code by running it in a browser console. Change the values of the varaiable a to change the returned `console.log()`.
122122

123123
## Logical Operators and Booleans
124124

@@ -137,15 +137,14 @@ Logical operators can be used to form conditions in if..else statements.
137137
```javascript
138138
let currentMoney;
139139
let laptopPrice;
140-
let laptopDiscountPrice = laptopPrice - (laptopPrice * .20) //Laptop price at 20 percent off
140+
let laptopDiscountPrice = laptopPrice - laptopPrice * 0.2; //Laptop price at 20 percent off
141141

142-
if (currentMoney >= laptopPrice || currentMoney >= laptopDiscountPrice){
143-
//Condition is true. Code in this block will run.
144-
console.log("Getting a new laptop!");
145-
}
146-
else {
147-
//Condition is true. Code in this block will run.
148-
console.log("Can't afford a new laptop, yet!");
142+
if (currentMoney >= laptopPrice || currentMoney >= laptopDiscountPrice) {
143+
//Condition is true. Code in this block will run.
144+
console.log("Getting a new laptop!");
145+
} else {
146+
//Condition is true. Code in this block will run.
147+
console.log("Can't afford a new laptop, yet!");
149148
}
150149
```
151150

@@ -173,17 +172,18 @@ Below is a more tangible example:
173172

174173
```javascript
175174
let firstNumber = 20;
176-
let secondNumber = 10
177-
let biggestNumber = firstNumber > secondNumber ? firstNumber: secondNumber;
175+
let secondNumber = 10;
176+
let biggestNumber = firstNumber > secondNumber ? firstNumber : secondNumber;
178177
```
179178

180179
✅ Take a minute to read this code a few times. Do you understand how these operators are working?
181180

182-
The above states that
183-
- if `firstNumber` is larger than `secondNumber`
184-
- then assign `firstNumber` to `biggestNumber`
185-
- else assign `secondNumber`.
186-
181+
The above states that
182+
183+
- if `firstNumber` is larger than `secondNumber`
184+
- then assign `firstNumber` to `biggestNumber`
185+
- else assign `secondNumber`.
186+
187187
The ternary expression is just a compact way of writing the code below:
188188

189189
```javascript
@@ -202,7 +202,9 @@ if (firstNumber > secondNumber) {
202202
Create a program that is written first with logical operators, and then rewrite it using a ternary expression. What's your preferred syntax?
203203

204204
---
205+
205206
## Post-Lecture Quiz
207+
206208
[Post-lecture quiz](https://ashy-river-0debb7803.1.azurestaticapps.net/quiz/12)
207209

208210
## Review & Self Study

0 commit comments

Comments
 (0)