diff --git a/Chapter 1/Exercise 1.2 b/Chapter 1/Exercise 1.2 new file mode 100644 index 0000000..90d4616 --- /dev/null +++ b/Chapter 1/Exercise 1.2 @@ -0,0 +1,14 @@ + + + + + Tester + + + + + + + diff --git a/Chapter 1/Exercise 1.3 b/Chapter 1/Exercise 1.3 new file mode 100644 index 0000000..6fd5f5b --- /dev/null +++ b/Chapter 1/Exercise 1.3 @@ -0,0 +1,12 @@ + + + + + Tester + + + + + + + diff --git a/Chapter 1/Exercise 1.4 b/Chapter 1/Exercise 1.4 new file mode 100644 index 0000000..9dfe78f --- /dev/null +++ b/Chapter 1/Exercise 1.4 @@ -0,0 +1,7 @@ +let a = 10; // assign a value of 10 to variable a +console.log(a); // This will output 10 into the console +/* +This is a multi-line +Comment +*/ + diff --git a/Chapter 1/Project 1 b/Chapter 1/Project 1 new file mode 100644 index 0000000..0c8bcee --- /dev/null +++ b/Chapter 1/Project 1 @@ -0,0 +1,15 @@ + + + + JS Tester + + + + + + +// console.log("Laurence"); +/* +This is my comment +Laurence Svekis +*/ diff --git a/Chapter 2/Exercise 2.1 b/Chapter 2/Exercise 2.1 index 8b13789..1f0ea10 100644 --- a/Chapter 2/Exercise 2.1 +++ b/Chapter 2/Exercise 2.1 @@ -1 +1,13 @@ +let str1 = 'Laurence'; +let str2 = "Svekis"; +let val1 = undefined; +let val2 = null; +let myNum = 1000; + + +console.log(typeof(str1)); +console.log(typeof(str2)); +console.log(typeof(val1)); +console.log(typeof(val2)); +console.log(typeof(myNum)); diff --git a/Chapter 2/Exercise 2.2 b/Chapter 2/Exercise 2.2 new file mode 100644 index 0000000..b23f19b --- /dev/null +++ b/Chapter 2/Exercise 2.2 @@ -0,0 +1,5 @@ +const myName = "Maaike"; +const myAge = 29; +const coder = true; +const message = "Hello, my name is " + myName + ", I am " + myAge+" years old and I can code JavaScript: " + coder + "."; +console.log(message); diff --git a/Chapter 2/Exercise 2.3 b/Chapter 2/Exercise 2.3 new file mode 100644 index 0000000..4828514 --- /dev/null +++ b/Chapter 2/Exercise 2.3 @@ -0,0 +1,6 @@ +let a = window.prompt("Value 1?"); +let b = window.prompt("Value 2?"); +a = Number(a); +b = Number(b); +let hypotenuseVal = ((a * a) + (b * b))**0.5; +console.log(hypotenuseVal); diff --git a/Chapter 2/Exercise 2.4 b/Chapter 2/Exercise 2.4 new file mode 100644 index 0000000..2e78578 --- /dev/null +++ b/Chapter 2/Exercise 2.4 @@ -0,0 +1,7 @@ +let a = 4; +let b = 11; +let c = 21; +a = a + b; +a = a / c; +c = c % b; +console.log(a, b, c); diff --git a/Chapter 2/Project 1 b/Chapter 2/Project 1 new file mode 100644 index 0000000..1d707a6 --- /dev/null +++ b/Chapter 2/Project 1 @@ -0,0 +1,5 @@ +//Convert miles to kilometers. +//1 mile equals 1.60934 kilometers. +let myDistanceMiles = 130; +let myDistanceKM = myDistanceMiles * 1.60934; +console.log("The distance of " + myDistanceMiles + " miles is equal to " + myDistanceKM + " kilometers") diff --git a/Chapter 2/Project 2 b/Chapter 2/Project 2 new file mode 100644 index 0000000..507805a --- /dev/null +++ b/Chapter 2/Project 2 @@ -0,0 +1,9 @@ +//1 inch = 2.54 centimetres. +//2.2046 pounds in a kilo +let inches = 72; +let pounds = 180; +let weight = pounds / 2.2046; // in kilos +let height = inches * 2.54; // height in centimetres +console.log(weight, height); +let bmi = weight/(height/100*height/100); +console.log(bmi); diff --git a/Chapter 3/Exercise 3.1 b/Chapter 3/Exercise 3.1 new file mode 100644 index 0000000..4e976b8 --- /dev/null +++ b/Chapter 3/Exercise 3.1 @@ -0,0 +1,4 @@ +const myList = ["Milk", "Bread", "Apples"]; +console.log(myList.length); +myList[1] = "Bananas"; +console.log(myList); diff --git a/Chapter 3/Exercise 3.2 b/Chapter 3/Exercise 3.2 new file mode 100644 index 0000000..5d09742 --- /dev/null +++ b/Chapter 3/Exercise 3.2 @@ -0,0 +1,12 @@ +const myList = []; +myList.push("Milk", "Bread", "Apples"); +myList.splice(1, 1, "Bananas", "Eggs"); +const removeLast = myList.pop(); +console.log(removeLast); +myList.sort(); +console.log(myList.indexOf("Milk")); +myList.splice(1, 0, "Carrots", "Lettuce"); +const myList2 = ["Juice", "Pop"]; +const finalList = myList.concat(myList2, myList2); +console.log(finalList.lastIndexOf("Pop")); +console.log(finalList); diff --git a/Chapter 3/Exercise 3.3 b/Chapter 3/Exercise 3.3 new file mode 100644 index 0000000..2c5c49e --- /dev/null +++ b/Chapter 3/Exercise 3.3 @@ -0,0 +1,5 @@ +const myArr = [1, 2, 3]; +const bigArr = [myArr, myArr, myArr]; +console.log(bigArr[1][1]); +console.log(bigArr[0][1]); +console.log(bigArr[2][1]); diff --git a/Chapter 3/Exercise 3.4 b/Chapter 3/Exercise 3.4 new file mode 100644 index 0000000..fec4127 --- /dev/null +++ b/Chapter 3/Exercise 3.4 @@ -0,0 +1,15 @@ +const myCar = { + make: "Toyota", + model: "Camry", + tires: 4, + doors: 4, + color: "blue", + forSale: false +}; + +let propColor = "color"; +myCar[propColor] = "red"; +propColor = "forSale"; +myCar[propColor] = true; +console.log(myCar.make + " " + myCar.model); +console.log(myCar.forSale); diff --git a/Chapter 3/Exercise 3.5 b/Chapter 3/Exercise 3.5 new file mode 100644 index 0000000..ffde2ce --- /dev/null +++ b/Chapter 3/Exercise 3.5 @@ -0,0 +1,6 @@ +const people = {friends:[]}; +const friend1 = {first: "Laurence", last: "Svekis", id: 1}; +const friend2 = {first: "Jane", last: "Doe", id: 2}; +const friend3 = {first: "John", last: "Doe", id: 3}; +people.friends.push(friend1, friend2, friend3); +console.log(people); diff --git a/Chapter 3/Project 1 b/Chapter 3/Project 1 new file mode 100644 index 0000000..20600fb --- /dev/null +++ b/Chapter 3/Project 1 @@ -0,0 +1,7 @@ +theList.pop(); +theList.shift(); +theList.unshift("FIRST"); +theList[3] = "hello World"; +theList[2] = "MIDDLE"; +theList.push("LAST"); +console.log(theList); diff --git a/Chapter 3/Project 2 b/Chapter 3/Project 2 new file mode 100644 index 0000000..3bf6d48 --- /dev/null +++ b/Chapter 3/Project 2 @@ -0,0 +1,22 @@ +const inventory = []; +const item3 = { + name: "computer", + model: "imac", + cost: 1000, + qty: 3 +} +const item2 = { + name: "phone", + model: "android", + cost: 500, + qty: 11 +} +const item1 = { + name: "tablet", + model: "ipad", + cost: 650, + qty: 1 +} +inventory.push(item1, item2, item3); +console.log(inventory); +console.log(inventory[2].qty); diff --git a/Chapter 4/Exercise 4.1 b/Chapter 4/Exercise 4.1 new file mode 100644 index 0000000..28dc50c --- /dev/null +++ b/Chapter 4/Exercise 4.1 @@ -0,0 +1,8 @@ +const test = false; +console.log(test); +if(test){ + console.log("It's True"); +} +if(!test){ + console.log("False now"); +} diff --git a/Chapter 4/Exercise 4.2 b/Chapter 4/Exercise 4.2 new file mode 100644 index 0000000..6b4a0c2 --- /dev/null +++ b/Chapter 4/Exercise 4.2 @@ -0,0 +1,11 @@ +let age = prompt("How old are you?"); +age = Number(age); +let message; +if(age >= 21){ + message = "You can enter and drink."; +}else if(age >= 19){ + message = "You can enter but not drink."; +}else{ + message = "You are not allowed in!"; +} +console.log(message); diff --git a/Chapter 4/Exercise 4.3 b/Chapter 4/Exercise 4.3 new file mode 100644 index 0000000..e450dc8 --- /dev/null +++ b/Chapter 4/Exercise 4.3 @@ -0,0 +1,3 @@ +const id = true; +const message = (id) ? "Allowed In" : "Denied Entry"; +console.log(message); diff --git a/Chapter 4/Exercise 4.4 b/Chapter 4/Exercise 4.4 new file mode 100644 index 0000000..4de299f --- /dev/null +++ b/Chapter 4/Exercise 4.4 @@ -0,0 +1,21 @@ +const randomNumber = Math.floor(Math.random() * 6); +let answer = "Something went wrong"; +let question = prompt("Ask me anything"); +switch (randomNumber) { + case 0: + answer = "It will work out"; + break; + case 1: + answer = "Maybe, maybe not"; + break; + case 2: + answer = "Probably not"; + break; + case 3: + answer = "Highly likely"; + break; + default: + answer = "I don't know about that"; +} +let output = "You asked me " + question + ". I think that " + answer; +console.log(output); diff --git a/Chapter 4/Exercise 4.5 b/Chapter 4/Exercise 4.5 new file mode 100644 index 0000000..444e180 --- /dev/null +++ b/Chapter 4/Exercise 4.5 @@ -0,0 +1,22 @@ +let prize = prompt("Pick a number 0-10"); +prize = Number(prize); +let output = "My Selection: "; +switch (prize){ + case 0: + output += "Gold "; + case 1: + output += "Coin "; + break; + case 2: + output += "Big "; + case 3: + output += "Box of "; + case 4: + output += "Silver "; + case 5: + output += "Bricks "; + break; + default: + output += "Sorry Try Again"; +} +console.log(output); diff --git a/Chapter 4/Project 1 b/Chapter 4/Project 1 new file mode 100644 index 0000000..f766b6c --- /dev/null +++ b/Chapter 4/Project 1 @@ -0,0 +1,13 @@ +let val = prompt("What number?"); +val = Number(val); +let num = 100; +let message = "nothing"; +if (val > num) { + message = val + " was greater than " + num; +} else if (val === num) { + message = val + " was equal to " + num; +} else { + message = val + " is less than " + num; +} +console.log(message); +console.log(message); diff --git a/Chapter 4/Project 2 b/Chapter 4/Project 2 new file mode 100644 index 0000000..561c6c5 --- /dev/null +++ b/Chapter 4/Project 2 @@ -0,0 +1,13 @@ +let person = prompt("Enter a name"); +let message; +switch (person) { + case "John" : + case "Larry" : + case "Jane" : + case "Laurence" : + message = person + " is my friend"; + break; + default : + message = "I don't know " + person; +} +console.log(message); diff --git a/Chapter 4/Project 3 b/Chapter 4/Project 3 new file mode 100644 index 0000000..fd92cb2 --- /dev/null +++ b/Chapter 4/Project 3 @@ -0,0 +1,20 @@ +const myArr = ["Rock", "Paper", "Scissors"]; +let computer = Math.floor(Math.random() * 3); +let player = Math.floor(Math.random() * 3); +let message = "player " + myArr[player] + " vs computer " + myArr[computer] + " "; +if (player === computer) { +message += "it's a tie"; +} else if (player > computer) { +if (computer == 0 && player == 2) { +message += "Computer Wins"; +} else { +message += "Player Wins"; +} +} else { +if (computer == 2 && player == 0) { +message += "Player Wins"; +} else { +message += "Computer Wins"; +} +} +console.log(message);