Skip to content

Commit 3a24374

Browse files
authored
Add files via upload
1 parent 07fa3a8 commit 3a24374

6 files changed

Lines changed: 218 additions & 0 deletions

File tree

Week2/1_ removeCOMMA.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
3+
let myString = 'hello,this,is,a,difficult,to,read,sentence';
4+
console.log(myString.length);
5+
6+
myString = myString.split(',').join(' ');
7+
console.log(myString);
8+
9+
10+
//Soluiton from shorturl.at/hyPV3
11+
12+
13+
14+
15+
//The method below works on arrays only??? :/
16+
//console.log(elements.join(' '));
17+
// expected output: "Fire-Air-Water"
18+
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join

Week2/2_eventOddREPORTER.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict'
2+
3+
//let numberReporter = 20;
4+
5+
for (let i = 1; i <= 20; i++) {
6+
if (i % 2 == 0) {
7+
console.log('The number is '+i+' even');
8+
} else {
9+
console.log('The number is '+i +' odd');
10+
}
11+
}
12+
13+
14+
15+
16+
17+
18+
/*
19+
20+
Things to think about:
21+
- It does not work without 'let'
22+
for (let i = 0; i < n; i++) {
23+
console.log(i);
24+
}
25+
26+
SOURCES REFERENCED
27+
https://www.w3resource.com/javascript-exercises/javascript-conditional-statements-and-loops-exercise-5.php
28+
29+
30+
for (let i = 0; i <= 15; i++) {
31+
console.log(i + ' is', (i % 2 == 0) ? "even" : "odd")
32+
}
33+
34+
*/

Week2/3_recipeCARD.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict'
2+
3+
const myReceipts = {
4+
Meal: 'Fried eggs',
5+
Servings: 2,
6+
Ingredients: ['Eggs (2x)', ' cooking oil', ' salt']
7+
};
8+
9+
// iterate over the user object
10+
for (const key in myReceipts) {
11+
console.log(`${key}: ${myReceipts[key]}`);
12+
}
13+
14+
15+
/*
16+
Source: https://attacomsian.com/blog/javascript-iterate-objects
17+
18+
*/

Week2/4_readingLIST.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use strict'
2+
3+
const books = [
4+
{
5+
title: 'Steppenwolf',
6+
alreadyRead: true,
7+
author: 'Hermann Hesse'
8+
},
9+
{
10+
title: 'Norwegian Wood',
11+
alreadyRead: true,
12+
author: 'Haruki Murakami'
13+
},
14+
{
15+
title: 'The Republic',
16+
alreadyRead: false,
17+
author: 'Plato'
18+
}
19+
];
20+
21+
22+
for(let i = 0; i < books.length; i = i + 1) {
23+
const book = books[i];
24+
// you print the title
25+
console.log(book.title + " by " + book.author);
26+
// if you read it then say i read it
27+
if (book.alreadyRead) { console.log("You already read " + book.title);
28+
// if you didn't read it then say still need to read
29+
} else {
30+
console.log("You still need to read " + book.title); }
31+
32+
// adds space in between the books. Let's give it a face lift!
33+
console.log("");
34+
}
35+
36+
37+
38+
39+
/*I still feel like this code is well above my capabilities. I will need to invest some more time into breakjng it down peice by piece.
40+
41+
let booksRead = [];
42+
for(let i = 0; i <= 2; i++) {
43+
const book = books[i];
44+
let sentence = book.title + " by " + book.author;
45+
console.log(sentence);
46+
if (book.alreadyRead) {
47+
booksRead.push("You already read " + book.title);
48+
} else {
49+
booksRead.push("You still need to read " + book.title);
50+
}
51+
}
52+
booksRead.forEach(sentence => console.log(sentence));
53+
54+
55+
56+
*/

Week2/5_wannaDRINK.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict'
2+
3+
const drinkTypes = ['cola', 'lemonade', 'water'];
4+
const drinkTray = [];
5+
6+
let drinkers = 10;
7+
8+
for (let i = 0; i <= drinkers - 1; i = i + 1) {
9+
const typeIndex = i % drinkTypes.length;
10+
drinkTray[i] = drinkTypes[typeIndex];}
11+
12+
console.log(`Hey guys, I brought a ${drinkTray.join(', ')}!`);
13+
14+
//Completed with a little help from a friend.
15+
16+
17+
/*
18+
const drinkTypes = ['cola', 'lemonade', 'water'];
19+
const drinkTray = [];
20+
21+
// let i = 0; i =< 4;i++
22+
// let i = 0; we start from number 0
23+
// i =< 4; the condition, we stop the loop as soon as the condition is no longer TRUTHY;
24+
// i++; incrementation; i += 1; i = i + 1;
25+
function countOccurences(drink, drinkTray) {
26+
let count = 0;
27+
drinkTray.forEach(drinkOnTray => {
28+
if (drinkOnTray === drink) {
29+
count++;
30+
}
31+
});
32+
return count;
33+
}
34+
35+
// Fixed solution, solving the problem but only for the specific numbers of 5
36+
for(let i = 0; i <= 4;i++) {
37+
if (i === 0 || i === 1) {
38+
drinkTray.push(drinkTypes[0]);
39+
} else if (i === 2 || i === 3) {
40+
drinkTray.push(drinkTypes[1]);
41+
} else {
42+
drinkTray.push(drinkTypes[2]);
43+
}
44+
}
45+
46+
console.log("IN DRINKTRAY", drinkTray);
47+
48+
// Dynamic solution, that will work any amount of drinks and conditions
49+
const numberPerDrink = 2;
50+
const totalDrinks = 5;
51+
52+
drinkTypes.forEach(drink => {
53+
for(let i = 0; i <= 1; i++) {
54+
if (drinkTray.length < totalDrinks) {
55+
drinkTray.push(drink);
56+
}
57+
}
58+
})
59+
60+
console.log("IN DRINKTRAY", drinkTray);
61+
62+
*/

Week2/6_gradeCALCULATOR.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict'
2+
3+
function yourGrade(pointsRECIEVED) {
4+
5+
let grade = (pointsRECIEVED/100)*100;
6+
7+
// Check if grade is an A, B, C, D, or F
8+
if (grade >= 90) {
9+
console.log("You got an A");
10+
} else if (grade >= 80) {
11+
console.log("You got a B");
12+
} else if (grade >= 70) {
13+
console.log("You got a C");
14+
} else if (grade >= 60) {
15+
console.log("You got a D. Take it easey! D - stand for a degree!");
16+
} else {
17+
console.log("F");
18+
}
19+
}
20+
21+
yourGrade(60);
22+
23+
24+
25+
26+
/*
27+
https://www.digitalocean.com/community/tutorials/how-to-write-conditional-statements-in-javascript
28+
29+
30+
*/

0 commit comments

Comments
 (0)