Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module-2-1-exercises #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
36 changes: 19 additions & 17 deletions lecture-2-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ Of course comparison operators and logical operators are usually combined in an
```js
// Look at these expressions below and determine whether they evaluate to true or false

1. true || false
2. false && false
3. 1 < 2 && 2 > 1
4. 31 < 13 || 1 < 2 && 3 > 1
5. 400 <= 400 && 399 < 400 && (30 > 31 || 400 > 31)
6. true && false && false || false && true
7. true && false || true || false
8. true && false && false || false && true ? true && false && false || false && true : 1 < 2 && 2 > 1
1. true || false TRUE
2. false && false FALSE
3. 1 < 2 && 2 > 1 TRUE
4. 31 < 13 || 1 < 2 && 3 > 1 TRUE
5. 400 <= 400 && 399 < 400 && (30 > 31 || 400 > 31) TRUE
6. true && false && false || false && true FALSE
7. true && false || true || false TRUE
8. true && false && false || false && true ? true && false && false || false && true : 1 < 2 && 2 > 1 TRUE
```

---
Expand Down Expand Up @@ -293,9 +293,9 @@ Given this data structure:
let data = [0, [], [], [1,2,3, [4]]]
```

1. How would you access the value `0`?
2. How would you access the value `3`?
3. How would you access the value `4`?
1. How would you access the value `0`? data[0]
2. How would you access the value `3`? data[3][2]
3. How would you access the value `4`? data[3][3][0]

---

Expand Down Expand Up @@ -341,6 +341,8 @@ Group the following items together according to their type:
- List the number of properties for each object.
- For each property, indicate its name and its value.
- For each property value, indicate the type.
--
- NOTE: **3 things: Property, key and value (Property is KEY AND VALUE COMBINED)**

```js
{ label: 'corn', price: 5.3 + '$' };
Expand Down Expand Up @@ -374,9 +376,9 @@ let person = {name: 'Bob', age: 23};
let name = 'John';

// What is the value of the following expressions?
1. person.name
2. person['name']
3. person[name]
1. person.name BOB
2. person['name'] BOB
3. person[name] UNDEFINED

```

Expand All @@ -391,9 +393,9 @@ let person = {name: 'bob', age: 23};
let key = 'name';

// What is the value of the following expressions:
1. person.key
2. person['key']
3. person[key]
1. person.key UNDEFINED
2. person['key'] UNDEFINED
3. person[key] BOB

```

Expand Down
40 changes: 40 additions & 0 deletions lecture-5-control-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,24 @@ Turn the following sentences into valid JavaScript `if` statements. _Use console
// 1. If it rains, I stay home.
let currentWeather = 'rainy';

if (currentWeather === "rainy) {
console.log("stay home");
}

// 2. If I am hungry, I eat.
let hunger = true;

if (hunger){
console.log("eat!");
}

// 3. If it's 10pm, I go to bed. If not, I write code.
let currentHour = 22;

if (currentHour >= 22) {
console.log("go to bed")
} else console.log ("write code");

```

## Loops
Expand Down Expand Up @@ -181,6 +193,14 @@ Write a program that output all of the numbers from 0 to 25
```js
// code here

for(i=0; i<=25; i++) {
console.log(i);
}





```

---
Expand All @@ -192,6 +212,18 @@ Write a program that output all of ODD the numbers from 0 to 25
```js
// code here

for(i=0; i<26; i++) {
if (i % 2 === 1) {
console.log(i);
}
}
OR

for(let i=0; i<26; 2++) {
console.log(i)
}


```

---
Expand All @@ -203,6 +235,14 @@ Write a program that output all of the numbers from 0 to 25, but replaces all mu
```js
// code here

for(let i=0; i<26; i++){
if (i % 5 === 0 && i !== 0) {
console.log("five alive!");
} else {
console.log(i);
}
}

```

---
73 changes: 52 additions & 21 deletions workshop/2-types/2-questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,77 +4,108 @@

1. ( ) "I am a "Horse""
2. ( ) "I 'prefer' ducks'
3. ( ) 'Yes, duck is nice'
4. ( ) "Ah, but I\'m vegan!"
3. (X) 'Yes, duck is nice'
4. (X) "Ah, but I\'m vegan!"
5. ( ) 'You'll eat salad then'
6. ( ) 'Yes I\'ll eat salad'
6. (X) 'Yes I\'ll eat salad'
7. ( ) "I'm happy to hear that!"
8. ( ) "\"Happy to hear " + 'that" ' + "he says!"
9. ( ) “Hello world!”
9. (X) “Hello world!”


## Question 2: Rewrite below all of the strings that are not valid, and correct them to make them valid.

1. "I am a Horse"
2. "I prefer ducks"
5. 'You\'ll eat salad then'
7. "I\'m happy to hear that!"
8. "Happy to hear " + "that " + "he says!"


## Question 3: Which of the following expressions are true? Add an 'x' between the ( ) to indicate that it's true.

1. ( ) 7 == 2
2. ( ) 7 == 7
3. ( ) 7 == '7'
4. ( ) 7 != 0
5. ( ) 7 !== '7'
2. (X) 7 == 7
3. (X) 7 == '7'
4. (X) 7 != 0
5. (X) 7 !== '7'
6. ( ) 7 != '7'
7. ( ) 7 != 7


## Question 4: Which of the following expressions is/are truthy?

1. ( ) !0
1. (X) !0
2. ( ) !1
3. ( ) -1
4. ( ) !"hello!"
5. ( ) null
6. ( ) !undefined
7. ( ) !NaN
6. (X) !undefined
7. (X) !NaN


## Question 5: Which of the following are valid objects?

1. ( ) {}
1. (X) {}
2. ( ) { 'hello' }
3. ( ) { name: 'I am fruit' }
4. ( ) {'brand-name': 'Dior' }
3. (X) { name: 'I am fruit' }
4. (X) {'brand-name': 'Dior' }
5. ( ) { brand-name: 'Channel' }
6. ( ) { cool_name: 'bob' + ' Dylan', age: 25 }
6. (X) { cool_name: 'bob' + ' Dylan', age: 25 }


## Question 6: For each array, specify the number of elements and the type of each element.

1. ['cat', 'dog', 'bird']
- number of elements:
- number of elements: 3
- type of _each_ element:
- 'cat':
- 'dog':
- 'bird':
- 'cat': string
- 'dog': string
- 'bird': string

2. [[], 24, 'hello', true]
- number: 4
- type
[]: array
24: number
"hello": string
"bird": string;

3. []
- empty array

4. [['romeo', 'juliet'], false]

- number of elements: 2
- type of _each_ element:
- '['romeo', 'juliet']': array with two strings
- false: boolean



5. [{name: 'bob', age: 23}, {name: 'paul', age: 33}]

- number: 2 objects



## Question 7: What is the type and value for each of the following variables?

1. let name = 'bob';
- type:
- value:
- type: string
- value: 'bob'

2. let age = 45;
- type: number
- value: 45

3. let isMarried = false;
- type: boolean
- value: false

4. let person = { name: name, age: age, isMarried: isMarried }
- type: object


5. let kids = [{name: 'Morty', age: 3}, {name: 'Summer', age: 7}]
- type: array of objects
4 changes: 2 additions & 2 deletions workshop/5-control-flow/5-exercise-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

// It is supposed to print to the console the numbers 1, 2, 3, 4, 5.

for (let number = 2; number < 5; number ++) {
for (let number = 1; number < 6; number++) {

console.log(number);
}
4 changes: 2 additions & 2 deletions workshop/5-control-flow/5-exercise-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Fix this program
// It should output the squares of all numbers between 0 and 12

for (let number = 0; number < 12; number ++) {

for (let number = 0; number < 13; number++) {
let square = number * number;
console.log('the square of ', number, ' is ', square);
}
7 changes: 3 additions & 4 deletions workshop/5-control-flow/5-exercise-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
// It should output all of the odd numbers between 1 and 25 (including 1 and 25)


for (let number = 0; number < 25; number ++) {
if (number % 2) {
for (let number = 1; number < 26; number++) {

if (number % 2 === 1) {
console.log(number);
}
console.log(number);
}
4 changes: 4 additions & 0 deletions workshop/5-control-flow/5-exercise-4.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@

// Q4.1
// Write a loop that will print to the console all of the integers from 0 to 100.

for (i = 0; i < 101; i++) {
console.log(i);
}
4 changes: 4 additions & 0 deletions workshop/5-control-flow/5-exercise-4.2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@

// Q4.2
// Write a loop that will print to the console all of the integers from 5 to 100.

for (i = 5; i < 101; i++) {
console.log(i);
}
7 changes: 7 additions & 0 deletions workshop/5-control-flow/5-exercise-4.3.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@

// Q4.3
// Write a loop that will print to the console all of the EVEN integers from 1 to 100.

for (let number = 1; number < 101; number++) {

if (number % 2 === 0) {
console.log(number);
}
}
7 changes: 7 additions & 0 deletions workshop/5-control-flow/5-exercise-4.4.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@

// Q4.4
// Write a loop that will print to the console all of the EVEN integers from 100 to 0.

for (let number = 100; number >= 0; number--) {

if (number % 2 === 0) {
console.log(number);
}
}
8 changes: 8 additions & 0 deletions workshop/5-control-flow/5-exercise-4.5.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
// 2 is even
// ...

for (i = 0; i < 16; i++) {
if (i % 2 === 0) {
console.log(`${i} is even`)
} else console.log(`${i} is odd`)
}





// many other possibilities here.
8 changes: 8 additions & 0 deletions workshop/5-control-flow/5-exercise-5.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@
// It's 11h. Time to train!
// It's 12h. Time to train!
// It's 13h. Time to eat!

for (i = 0; i < 24; i++) {
if (i > 21 || i <= 5) {
console.log(`It's ${i}h. Time to sleep!`)
} else if (i === 7 || i === 13 || i === 18) {
console.log(`It's ${i}h. Time to eat!`)
} else console.log(`It's ${i}h. Time to train!`)
}
11 changes: 10 additions & 1 deletion workshop/5-control-flow/5-exercise-6.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@
// Write a program that will output the sum of all of the multiples of four
// between 0 and 5000
//
// ANSWER: the number you should see in the console is 3127500
// ANSWER: the number you should see in the console is 3127500


let sum = 0;

for (i = 0; i < 5001; i = 4 + i) {
sum = sum + i;
}

console.log(sum);
Loading