From bb98391dc308258bbf4259594e400cf0589ca124 Mon Sep 17 00:00:00 2001 From: aishak05 Date: Tue, 19 Jan 2021 23:48:02 +0000 Subject: [PATCH 1/5] Exercises --- exercises/B-hello-world/README.md | 14 +++++++------- exercises/B-hello-world/exercise.js | 3 +++ exercises/C-variables/exercise.js | 5 +++++ exercises/D-strings/exercise.js | 4 ++++ exercises/E-strings-concatenation/exercise.js | 7 ++++++- exercises/F-strings-methods/exercise.js | 6 +++++- exercises/F-strings-methods/exercise2.js | 4 +++- exercises/G-numbers/exercise.js | 7 +++++++ 8 files changed, 40 insertions(+), 10 deletions(-) diff --git a/exercises/B-hello-world/README.md b/exercises/B-hello-world/README.md index a7b891d56..e50838e5d 100644 --- a/exercises/B-hello-world/README.md +++ b/exercises/B-hello-world/README.md @@ -6,13 +6,13 @@ Inside of `exercise.js` there's a line of code that will print "Hello world!". ### 1. Run the program -* Open a terminal window -* Change directory to this folder (`cd B-hello-world`) -* Run the program using node (`node exercise.js`) +- Open a terminal window +- Change directory to this folder (`cd B-hello-world`) +- Run the program using node (`node exercise.js`) ### 2. Experiment -* Try to `console.log()` something different. For example, 'Hello World. I just started learning JavaScript!'. -* Try to console.log() several things at once. -* What happens when you get rid of the quote marks? -* What happens when you console.log() just a number without quotes? +- Try to `console.log()` something different. For example, 'Hello World. I just started learning JavaScript!'. +- Try to console.log() several things at once. +- What happens when you get rid of the quote marks? You get a syntax error +- What happens when you console.log() just a number without quotes? It prints the number diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..9c834f4d6 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,4 @@ console.log("Hello world"); +console.log('Hello World. I just started learning JavaScript!'); +console.log("My name is Aisha"); +console.log(25); \ No newline at end of file diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..83c8c223a 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,8 @@ // Start by creating a variable `greeting` + +var greeting = "Hello World" + +console.log(greeting); +console.log(greeting); console.log(greeting); diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..64997259d 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,7 @@ // Start by creating a variable `message` +var message = "This is a string"; +var messageType = typeof message; + console.log(message); +console.log(messageType); diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..933ff5853 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,8 @@ // Start by creating a variable `message` -console.log(message); +var greetingStart = "Hello, my name is "; +var name = "Aisha"; + +var greeting = greetingStart + name; + +console.log(greeting); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..4a7c4f01a 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,7 @@ // Start by creating a variable `message` -console.log(message); +var name = "Aisha"; +var nameLength = name.length; +var message = "My name is " + name + " and the length of name is " +nameLength +" characters long." + +console.log(message); \ No newline at end of file diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..cd02a37d8 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,5 @@ const name = " Daniel "; +var nameLength = name.length; +message = "My name is " + name+" and my name is "+ nameLength + " characters long" -console.log(message); +console.log(message.trim()); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..aa8270e7e 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,8 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` + +const numberOfStudents = 15; +const numberOfMentors = 8; +const sum = numberOfStudents + umberOfMentors; + +console.log(sum); + From 2ffb01c31279d6516aa0a0d3b208081543897597 Mon Sep 17 00:00:00 2001 From: aishak05 Date: Tue, 19 Jan 2021 23:56:55 +0000 Subject: [PATCH 2/5] floats exercise --- exercises/G-numbers/exercise.js | 5 ++--- exercises/I-floats/exercise.js | 11 +++++++++++ exercises/J-functions/README.md | 6 +++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index aa8270e7e..84a4b4f42 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -2,7 +2,6 @@ const numberOfStudents = 15; const numberOfMentors = 8; -const sum = numberOfStudents + umberOfMentors; - -console.log(sum); +const sum = numberOfStudents + numberOfMentors; +console.log("The total number of students and mentors is " + sum); \ No newline at end of file diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..54d6b557b 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,13 @@ var numberOfStudents = 15; var numberOfMentors = 8; + +const sum = numberOfStudents+ numberOfMentors; + + +const percentageStudents = numberOfStudents / sum *100; +const roughPercentageStudents = Math.round(percentageStudents); +console.log(roughPercentageStudents); + +const percentageMentors = numberOfMentors / sum *100; +const roughPercentageMentors = Math.round(percentageMentors); +console.log(roughPercentageMentors); diff --git a/exercises/J-functions/README.md b/exercises/J-functions/README.md index a5c765cef..22105ca2a 100644 --- a/exercises/J-functions/README.md +++ b/exercises/J-functions/README.md @@ -20,8 +20,8 @@ console.log(result); // 4 ## Exercise -* Complete the function in exercise.js so that it halves the input -* Try calling the function more than once with some different numbers +- Complete the function in exercise.js so that it halves the input +- Try calling the function more than once with some different numbers > Remember to use the return keyword to get a value out of the function @@ -33,7 +33,7 @@ console.log(result); // 4 ## Exercise 2 -* Complete the function in exercise2.js so that it triples the input +- Complete the function in exercise2.js so that it triples the input ## Expected result From 7ee78fee7f579e7a1150e6df4ac4a997236a3584 Mon Sep 17 00:00:00 2001 From: aishak05 Date: Wed, 20 Jan 2021 22:00:27 +0000 Subject: [PATCH 3/5] functions --- exercises/J-functions/exercise.js | 6 ++- exercises/J-functions/exercise2.js | 2 +- exercises/K-functions-parameters/exercise.js | 4 +- exercises/K-functions-parameters/exercise2.js | 6 ++- exercises/K-functions-parameters/exercise3.js | 5 ++- exercises/K-functions-parameters/exercise4.js | 5 +++ exercises/K-functions-parameters/exercise5.js | 4 ++ exercises/L-functions-nested/exercise.js | 39 ++++++++++++++++--- 8 files changed, 59 insertions(+), 12 deletions(-) diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..db8ef46c4 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,7 +1,11 @@ function halve(number) { - // complete the function here + return number/2; } var result = halve(12); + +console.log(result); + +var result = halve(40); console.log(result); diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..a57a8d69a 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,5 +1,5 @@ function triple(number) { - // complete function here + return number*3; } var result = triple(12); diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..1c4947028 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,6 +1,6 @@ // Complete the function so that it takes input parameters -function multiply() { - // Calculate the result of the function and return it +function multiply(num1,num2) { + return num1*num2; } // Assign the result of calling the function the variable `result` diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..d66d97e92 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,5 +1,7 @@ -// Declare your function first - +function divide(num1,num2){ + return num1/num2; +} + var result = divide(3, 4); console.log(result); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..a190e5210 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,4 +1,7 @@ -// Write your function here +function createGreeting(name) { + const message = "Hello, my name is " + name; + return message; +} var greeting = createGreeting("Daniel"); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..13a99e900 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,10 @@ // Declare your function first +function add (num1,num2){ + return num1+num2; +} // Call the function and assign to a variable `sum` +var sum = add(13,124); + console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..8fd94ebd5 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,4 +1,8 @@ // Declare your function here +function createLongGreeting(name,age){ + var message = "Hello, my name is " + name + " and I'm " + age + " years old." + return message; +} const greeting = createLongGreeting("Daniel", 30); diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..5ac050ef7 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -1,5 +1,34 @@ -var mentor1 = "Daniel"; -var mentor2 = "Irina"; -var mentor3 = "Mimi"; -var mentor4 = "Rob"; -var mentor5 = "Yohannes"; + +function calculatePercent(num,sum) { + return Math.round(num/sum *100); +} + +var percentageOfStudents = calculatePercent(15,23); +var percentageOfMentors = calculatePercent(8,23); + + +function percentageMessage(individual,percentage){ + message = "The percentage of " +individual + " is " + percentage +"%."; + return message; + +} + +console.log(percentageMessage("students",percentageOfStudents)); +console.log(percentageMessage("mentors",percentageOfMentors)); + + +function greeting(name){ + return "HELLO " + name; +} + + var mentor1 = "Daniel"; + var mentor2 = "Irina"; + var mentor3 = "Mimi"; + var mentor4 = "Rob"; + var mentor5 = "Yohannes"; + +console.log(greeting(mentor1)); +console.log(greeting(mentor2)); +console.log(greeting(mentor3)); +console.log(greeting(mentor4)); +console.log(greeting(mentor5)); From f0a971d1876fae25d910f7ab8176096b88592e71 Mon Sep 17 00:00:00 2001 From: aishak05 Date: Wed, 20 Jan 2021 22:55:09 +0000 Subject: [PATCH 4/5] passed tests --- mandatory/1-syntax-errors.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index 0a21afd1b..1eee09074 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,16 +1,17 @@ // There are syntax errors in this code - can you fix it to pass the tests? -function addNumbers(a b c) { +function addNumbers(a, b, c) { return a + b + c; } -function introduceMe(name, age) -return "Hello, my name is " + name "and I am " age + "years old"; +function introduceMe(name, age){ +return "Hello, my name is " + name + " and I am " + age + " years old"; +} function getTotal(a, b) { - total = a ++ b; + total = a + b; - return "The total is total" + return "The total is " + total; } /* From fda014c1ad6d5fddd4946428281b8d0fce48650e Mon Sep 17 00:00:00 2001 From: aishak05 Date: Wed, 20 Jan 2021 22:55:57 +0000 Subject: [PATCH 5/5] Update exercise.js --- exercises/C-variables/exercise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index 83c8c223a..b8add2512 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,7 +1,7 @@ // Start by creating a variable `greeting` -var greeting = "Hello World" +var greeting = "Hello World"; console.log(greeting); console.log(greeting);