diff --git a/.DS_Store b/.DS_Store index d06ffd2ea..28d7aad28 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Week2/.DS_Store b/Week2/.DS_Store new file mode 100644 index 000000000..8a363d1aa Binary files /dev/null and b/Week2/.DS_Store differ diff --git a/Week2/Grade_Calculator.js b/Week2/Grade_Calculator.js new file mode 100644 index 000000000..e69de29bb diff --git a/Week2/js-exercises/oddOrEven.js b/Week2/js-exercises/oddOrEven.js new file mode 100644 index 000000000..86d70165e --- /dev/null +++ b/Week2/js-exercises/oddOrEven.js @@ -0,0 +1,22 @@ +/* +Exercise 2: The even/odd reporter + +Report whether or not a number is odd/even! + +Create a for loop, that iterates from 0 to 20. +Create a conditional statement that checks if the value of the counter variable is odd or even. +If it's odd, log to the console The number [PUT_NUMBER_HERE] is odd!. +If it's even, log to the console The number [PUT_NUMBER_HERE] is even!.*/ + +'use strict' + +for (var i = 0; i < 21; i++) { + if (i === 0) { + console.log(`The number ${i} is 0`); + } + else if (i % 2 === 0) { + console.log(`The number ${i} is even~`); + } else { + console.log(`The number ${i} is odd`); + } +} \ No newline at end of file diff --git a/Week2/js-exercises/readingList.js b/Week2/js-exercises/readingList.js new file mode 100644 index 000000000..f329d603f --- /dev/null +++ b/Week2/js-exercises/readingList.js @@ -0,0 +1,27 @@ +/* +Exercise 4: The reading list + +Keep track of which books you read and which books you want to read! + +Declare a variable that holds an array of 3 objects, where each object describes a book and has properties +for the title (string), author (string), and alreadyRead (boolean indicating if you read it yet). + +Loop through the array of books. +For each book, log the book title and book author like so: "The Hobbit by J.R.R. Tolkien". + +Create a conditional statement to change the log depending on whether you read it yet or not. If you read +it, log a string like You already read "The Hobbit" right after the log of the book details +If you haven't read it log a string like You still need to read "The Lord of the Rings"*/ + +'use strict' + +let books = [ + {title: "Homer", author: 'Aristotle', alreadyRead: true }, + {title: "Sex Psychology", author: 'Freud', alreadyRead: false }, + {title: "Steve Coogan AutoBiography", author: 'Steven Coogan', alreadyRead: false } +]; + +for (var i = 0; i < books.length; i++) { + console.log(books[i]); +} + diff --git a/Week2/js-exercises/recipeCard.js b/Week2/js-exercises/recipeCard.js new file mode 100644 index 000000000..16513fb33 --- /dev/null +++ b/Week2/js-exercises/recipeCard.js @@ -0,0 +1,31 @@ +/* Exercise 3: The recipe card + +Ever wondered how to make a certain meal? Let's create a recipe list with JavaScript! + +Declare a variable that holds an object (your meal recipe). +Give the object 3 properties: a title (string), a servings (number) and an ingredients (array of strings) property. +Log each property out seperately, using a loop (for, while or do/while) +It should look similar to this: + +Meal name: Omelete +Serves: 2 +Ingredients: +4 eggs +2 strips of bacon +1 tsp salt/pepper */ + +'use strict' + +let mealRecipe = { + "title":'My meal title', + "servings": 4, + "ingredients": ['sugar', 'water', 'purple'] +} + +/*for (i = 0; i <= 2; i ++) { + console.log(mealRecipe.title + "\n"); +}*/ + +for (var key in mealRecipe) { + console.log(key + ' : ' + mealRecipe[key]); +} \ No newline at end of file diff --git a/Week2/js-exercises/removeComma.js b/Week2/js-exercises/removeComma.js new file mode 100644 index 000000000..788d46a2e --- /dev/null +++ b/Week2/js-exercises/removeComma.js @@ -0,0 +1,21 @@ +'use strict' + +/*Exercise 1: Remove the comma + +Consider the following string: + +let myString = 'hello,this,is,a,difficult,to,read,sentence'; +Add the variable to your file. +Log the length of myString. +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!) +After replacing the commas, log myString to see if you succeeded.*/ + +let myString = 'hello,this,is,a,difficult,to,read,sentence'; + +console.log(myString.length); + +let space = " "; + +myString = myString.split(",").join(space); + +console.log(myString); \ No newline at end of file diff --git a/homework/.DS_Store b/homework/.DS_Store new file mode 100644 index 000000000..4a4be8388 Binary files /dev/null and b/homework/.DS_Store differ diff --git a/homework/js-exercises/6.js b/homework/js-exercises/6.js new file mode 100644 index 000000000..ef6add839 --- /dev/null +++ b/homework/js-exercises/6.js @@ -0,0 +1,7 @@ +var animals = []; +console.log('value of the array is undefined, it exists but holds no values'); +console.log(animals); +var threeFaveAnimals = ['Lemur', 'Indris', 'Lion']; +console.log(threeFaveAnimals); +animals.push('Piglet'); +console.log(animals); \ No newline at end of file diff --git a/homework/js-exercises/7.js b/homework/js-exercises/7.js new file mode 100644 index 000000000..f894b8237 --- /dev/null +++ b/homework/js-exercises/7.js @@ -0,0 +1,3 @@ +const mySentence = 'Programming is so interesting!'; + +console.log(mySentence.length); \ No newline at end of file diff --git a/homework/js-exercises/8.js b/homework/js-exercises/8.js new file mode 100644 index 000000000..9dd0b42bc --- /dev/null +++ b/homework/js-exercises/8.js @@ -0,0 +1,34 @@ +const stringOne = 'Hi'; +const stringTwo = 'Bye'; +const objectOne = { + name: 'Cool', + iCanHoldNumbers: 420 +}; +const objectTwo = { + accent: 'English', + iCanHoldBooleans: false +}; + +function testType(d1, d2) { + if (typeof d1 === typeof d2) { + console.log('The two variables are of the same type'); + console.log('D1 is ' + typeof d1 + 'D2 is ' + typeof d2); + } else { + console.log('The two variables are NOT of the same type.'); + console.log('D1 is ' + typeof d1 + 'D2 is ' + typeof d2); + } +} + +testType(stringOne, objectOne); +testType(stringOne, stringTwo); +testType(objectOne, objectTwo); +testType(objectTwo, stringTwo); + +const fruits = ['apple', 'banana', 'pears', 'tomatos']; +const primeNumbers = [1, 2, 3, 5, 7]; + +if (fruits.length === primeNumbers.length) { + console.log('They are the same length. Yay!'); +} else { + console.log('They are not the same length, awww'); +} \ No newline at end of file