Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit e5d1312

Browse files
author
lo den
committed
praxis
1 parent ac2ff20 commit e5d1312

11 files changed

Lines changed: 145 additions & 0 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

Week2/.DS_Store

6 KB
Binary file not shown.

Week2/Grade_Calculator.js

Whitespace-only changes.

Week2/js-exercises/oddOrEven.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Exercise 2: The even/odd reporter
3+
4+
Report whether or not a number is odd/even!
5+
6+
Create a for loop, that iterates from 0 to 20.
7+
Create a conditional statement that checks if the value of the counter variable is odd or even.
8+
If it's odd, log to the console The number [PUT_NUMBER_HERE] is odd!.
9+
If it's even, log to the console The number [PUT_NUMBER_HERE] is even!.*/
10+
11+
'use strict'
12+
13+
for (var i = 0; i < 21; i++) {
14+
if (i === 0) {
15+
console.log(`The number ${i} is 0`);
16+
}
17+
else if (i % 2 === 0) {
18+
console.log(`The number ${i} is even~`);
19+
} else {
20+
console.log(`The number ${i} is odd`);
21+
}
22+
}

Week2/js-exercises/readingList.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Exercise 4: The reading list
3+
4+
Keep track of which books you read and which books you want to read!
5+
6+
Declare a variable that holds an array of 3 objects, where each object describes a book and has properties
7+
for the title (string), author (string), and alreadyRead (boolean indicating if you read it yet).
8+
9+
Loop through the array of books.
10+
For each book, log the book title and book author like so: "The Hobbit by J.R.R. Tolkien".
11+
12+
Create a conditional statement to change the log depending on whether you read it yet or not. If you read
13+
it, log a string like You already read "The Hobbit" right after the log of the book details
14+
If you haven't read it log a string like You still need to read "The Lord of the Rings"*/
15+
16+
'use strict'
17+
18+
let books = [
19+
{title: "Homer", author: 'Aristotle', alreadyRead: true },
20+
{title: "Sex Psychology", author: 'Freud', alreadyRead: false },
21+
{title: "Steve Coogan AutoBiography", author: 'Steven Coogan', alreadyRead: false }
22+
];
23+
24+
for (var i = 0; i < books.length; i++) {
25+
console.log(books[i]);
26+
}
27+

Week2/js-exercises/recipeCard.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* Exercise 3: The recipe card
2+
3+
Ever wondered how to make a certain meal? Let's create a recipe list with JavaScript!
4+
5+
Declare a variable that holds an object (your meal recipe).
6+
Give the object 3 properties: a title (string), a servings (number) and an ingredients (array of strings) property.
7+
Log each property out seperately, using a loop (for, while or do/while)
8+
It should look similar to this:
9+
10+
Meal name: Omelete
11+
Serves: 2
12+
Ingredients:
13+
4 eggs
14+
2 strips of bacon
15+
1 tsp salt/pepper */
16+
17+
'use strict'
18+
19+
let mealRecipe = {
20+
"title":'My meal title',
21+
"servings": 4,
22+
"ingredients": ['sugar', 'water', 'purple']
23+
}
24+
25+
/*for (i = 0; i <= 2; i ++) {
26+
console.log(mealRecipe.title + "\n");
27+
}*/
28+
29+
for (var key in mealRecipe) {
30+
console.log(key + ' : ' + mealRecipe[key]);
31+
}

Week2/js-exercises/removeComma.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict'
2+
3+
/*Exercise 1: Remove the comma
4+
5+
Consider the following string:
6+
7+
let myString = 'hello,this,is,a,difficult,to,read,sentence';
8+
Add the variable to your file.
9+
Log the length of myString.
10+
The commas make that the sentence is quite hard to read. Find a way to remove the commas from the string and replace them with spaces. (use Google!)
11+
After replacing the commas, log myString to see if you succeeded.*/
12+
13+
let myString = 'hello,this,is,a,difficult,to,read,sentence';
14+
15+
console.log(myString.length);
16+
17+
let space = " ";
18+
19+
myString = myString.split(",").join(space);
20+
21+
console.log(myString);

homework/.DS_Store

6 KB
Binary file not shown.

homework/js-exercises/6.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var animals = [];
2+
console.log('value of the array is undefined, it exists but holds no values');
3+
console.log(animals);
4+
var threeFaveAnimals = ['Lemur', 'Indris', 'Lion'];
5+
console.log(threeFaveAnimals);
6+
animals.push('Piglet');
7+
console.log(animals);

homework/js-exercises/7.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const mySentence = 'Programming is so interesting!';
2+
3+
console.log(mySentence.length);

0 commit comments

Comments
 (0)