From 9e0e01843bdde95c89e2c6cafc2169e45b97e48d Mon Sep 17 00:00:00 2001 From: Cecilia Date: Wed, 25 Nov 2020 13:59:05 +0000 Subject: [PATCH 1/8] Made exercises A_F --- exercises/B-hello-world/README.md | 14 +++++++------- exercises/B-hello-world/exercise.js | 3 ++- exercises/C-variables/README.md | 4 ++-- exercises/C-variables/exercise.js | 3 +++ exercises/D-strings/README.md | 2 +- exercises/D-strings/exercise.js | 2 ++ exercises/E-strings-concatenation/exercise.js | 6 +++++- exercises/F-strings-methods/exercise.js | 3 ++- exercises/F-strings-methods/exercise2.js | 2 +- 9 files changed, 25 insertions(+), 14 deletions(-) diff --git a/exercises/B-hello-world/README.md b/exercises/B-hello-world/README.md index 2ac9fe586..007fe32c1 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 week-1/C-hello-world`) -* Run the program using node (`node exercise.js`) +- Open a terminal window +- Change directory to this folder (`cd week-1/C-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? 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..c3374c133 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,2 @@ -console.log("Hello world"); +console.log("Hello World. I just started learning JavaScript!"); +console.log(2); diff --git a/exercises/C-variables/README.md b/exercises/C-variables/README.md index 26eccc1e8..7936084db 100644 --- a/exercises/C-variables/README.md +++ b/exercises/C-variables/README.md @@ -12,8 +12,8 @@ The program above will print "Hello world" to the console. Notice how it uses th ## Exercise -* Add a variable `greeting` to exercise.js (make sure it comes _before_ the console.log) -* Print your `greeting` to the console 3 times +- Add a variable `greeting` to exercise.js (make sure it comes _before_ the console.log) +- Print your `greeting` to the console 3 times > Remember: to run this exercise you must change directory to the `D-variables`. If you already have a terminal window open for the previous exercise you can do this by running the command `cd ../D-variables`. diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..628a44964 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,6 @@ // 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/README.md b/exercises/D-strings/README.md index 1516f536e..fd0a664ae 100644 --- a/exercises/D-strings/README.md +++ b/exercises/D-strings/README.md @@ -19,7 +19,7 @@ console.log(messageType); // logs 'string' ## Exercise -* Write a program that logs a message and its type +- Write a program that logs a message and its type ## Expected result diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..7d54e9903 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` +var message = "This is a string"; console.log(message); +console.log(typeof message); diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..e7994ed5d 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,7 @@ // Start by creating a variable `message` +var greetingStart = "Hello, my name is "; +var name = "Cecilia"; -console.log(message); +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..8279fe57c 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,4 @@ // Start by creating a variable `message` +var name = "Cecilia" -console.log(message); +console.log("My name is " + name + " and my name is " + name.length + " characters long"); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..2fa3aa87e 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,3 @@ const name = " Daniel "; -console.log(message); +console.log("My name is " + name.trim() + " and my name is " + name.trim().length + " characters long"); From d559168faf4e7c840feaa28cb50c8afcdff4775a Mon Sep 17 00:00:00 2001 From: Cecilia Date: Wed, 25 Nov 2020 18:56:57 +0000 Subject: [PATCH 2/8] Completed exercises G-L --- exercises/G-numbers/exercise.js | 6 ++++++ exercises/I-floats/exercise.js | 5 ++++- exercises/J-functions/exercise.js | 1 + exercises/J-functions/exercise2.js | 1 + exercises/K-functions-parameters/exercise.js | 3 ++- exercises/K-functions-parameters/exercise2.js | 3 +++ exercises/K-functions-parameters/exercise3.js | 3 +++ exercises/K-functions-parameters/exercise4.js | 5 ++++- exercises/K-functions-parameters/exercise5.js | 4 +++- exercises/L-functions-nested/exercise.js | 21 ++++++++++++++----- exercises/L-functions-nested/exercise2.js | 19 +++++++++++++++++ 11 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 exercises/L-functions-nested/exercise2.js diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..ef423ed0e 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,7 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +var numberOfStudents = 15; +var numberOfMentors = 8; + +console.log("Number of students: ",numberOfStudents); +console.log("Number of mentors: ", numberOfMentors); +console.log("Total number of students and mentors: ", numberOfMentors + numberOfStudents); diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..2621cb68a 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,5 @@ var numberOfStudents = 15; -var numberOfMentors = 8; +var numberOfMentors = 8; + +console.log("Percentage students:", Math.round(numberOfStudents/(numberOfStudents + numberOfMentors)*100)+"%"); +console.log("Percentage mentors:", Math.round(numberOfMentors/(numberOfStudents + numberOfMentors)*100)+"%"); \ No newline at end of file diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..e9ba2f0ef 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,5 +1,6 @@ function halve(number) { // complete the function here + return number/2; } var result = halve(12); diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..6d216ffc6 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,5 +1,6 @@ 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..e37f89d44 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,6 +1,7 @@ // Complete the function so that it takes input parameters -function multiply() { +function multiply(a,b) { // Calculate the result of the function and return it + return a*b; } // 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..02a698a36 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,4 +1,7 @@ // Declare your function first +function divide(a, b) { + return a/b; +} var result = divide(3, 4); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..6de0f0538 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(greet) { + return "Hello, my name is " + greet; +} var greeting = createGreeting("Daniel"); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..4e573f041 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,8 @@ // Declare your function first - +function addition(a,b) { + return a + b; +} // Call the function and assign to a variable `sum` +var sum = addition(13, 124); console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..f8678fb7f 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,7 @@ // Declare your function here - +function createLongGreeting(name, age) { + return "Hello, my name is "+ name + " and I'm " + age + " years old "; +} const greeting = createLongGreeting("Daniel", 30); console.log(greeting); diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..0fb873021 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -1,5 +1,16 @@ -var mentor1 = "Daniel"; -var mentor2 = "Irina"; -var mentor3 = "Mimi"; -var mentor4 = "Rob"; -var mentor5 = "Yohannes"; +var students = { "type": "students", "number": 15}; +var mentors = { "type": "mentors", "number": 8}; + +function calculatePercentage(a,b) { + return Math.round(a.number / (a.number + b.number) * 100); +} + +function createMessage(cat1, cat2) { + return "Percentage " + cat1.type + ": " + calculatePercentage(cat1, cat2) + "%"; +} + +var percentageOfStudents = createMessage(students, mentors); +var percentageOfMentors = createMessage(mentors, students); + +console.log(percentageOfStudents); +console.log(percentageOfMentors); \ No newline at end of file diff --git a/exercises/L-functions-nested/exercise2.js b/exercises/L-functions-nested/exercise2.js new file mode 100644 index 000000000..54059d6d6 --- /dev/null +++ b/exercises/L-functions-nested/exercise2.js @@ -0,0 +1,19 @@ +var mentor1 = "Daniel"; +var mentor2 = "Irina"; +var mentor3 = "Mimi"; +var mentor4 = "Rob"; +var mentor5 = "Yohannes"; + +function shoutName(name) { + return name.toUpperCase(); +} + +function shoutGreeting(mentor) { + return "HELLO " + shoutName(mentor); +} + +console.log(shoutGreeting(mentor1)); +console.log(shoutGreeting(mentor2)); +console.log(shoutGreeting(mentor3)); +console.log(shoutGreeting(mentor4)); +console.log(shoutGreeting(mentor5)); From a861076575eec202b279a4604d2af74c29729f9c Mon Sep 17 00:00:00 2001 From: Cecilia Date: Thu, 26 Nov 2020 09:07:53 +0000 Subject: [PATCH 3/8] Completed mandatory exercises --- mandatory/1-syntax-errors.js | 11 ++++++----- mandatory/2-logic-error.js | 7 +++---- mandatory/3-function-output.js | 3 +++ mandatory/4-tax.js | 9 +++++++-- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index fb756b637..f1095a765 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,17 +1,18 @@ // 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; + const total = a + b; // Use string interpolation here - return "The total is %{total}" + return `The total is ${total}`; } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index c8444605e..71118b8ee 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,16 +1,15 @@ // The syntax for this function is valid but it has an error, find it and fix it. function trimWord(word) { - return wordtrim(); + return word.trim(); } function getWordLength(word) { - return "word".length() + return word.length; } function multiply(a, b, c) { - a * b * c; - return; + return a * b * c; } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index c8e857707..8ad4f51f3 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,9 +1,11 @@ // Add comments to explain what this function does. You're meant to use Google! +// This function returns a random number >= 0 and < 10 function getNumber() { return Math.random() * 10; } // Add comments to explain what this function does. You're meant to use Google! +// This function returns the two input parameters concatenated (i.e. the second one following the first) function s(w1, w2) { return w1.concat(w2); } @@ -11,6 +13,7 @@ function s(w1, w2) { function concatenate(firstWord, secondWord, thirdWord) { // Write the body of this function to concatenate three words together. // Look at the test case below to understand what this function is expected to return. + return `${firstWord} ${secondWord} ${thirdWord}`; } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index 79db5409d..e8084ebb4 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,7 +5,9 @@ Sales tax is 20% of the price of the product */ -function calculateSalesTax() {} +function calculateSalesTax(price) { + return price += price * 0.2; +} /* CURRENCY FORMATTING @@ -17,7 +19,10 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(price) { + price = calculateSalesTax(price); + return `£${price.toFixed(2)}` +} /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. From b5ce3f8bcd6b0bfa0b004569ce924999daf1b69b Mon Sep 17 00:00:00 2001 From: Cecilia Date: Thu, 26 Nov 2020 11:38:24 +0000 Subject: [PATCH 4/8] Completed extra exercises 1 and 2 --- extra/1-currency-conversion.js | 8 ++++++-- extra/2-piping.js | 20 +++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index 5f0609722..8a22c6fa5 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -5,7 +5,9 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -function convertToUSD() {} +function convertToUSD(price) { + return price * 1.4; +} /* CURRENCY FORMATTING @@ -15,7 +17,9 @@ function convertToUSD() {} They have also decided that they should add a 1% fee to all foreign transactions, which means you only convert 99% of the £ to BRL. */ -function convertToBRL() {} +function convertToBRL(price) { + return price * 0.99 * 5.7; +} /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. diff --git a/extra/2-piping.js b/extra/2-piping.js index 067dd0f5b..37056644e 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -16,26 +16,28 @@ the final result to the variable goodCode */ -function add() { - +function add(a, b) { + return a + b; } -function multiply() { - +function multiply(a, b) { + return a * b; } -function format() { - +function format(num) { + return `£${num}`; } const startingValue = 2 // Why can this code be seen as bad practice? Comment your answer. -let badCode = +// It is not clear what's going on for someone who is not familiar with the code. +let badCode = format(multiply(add(startingValue, 10), 2)); /* BETTER PRACTICE */ - -let goodCode = +let addedValue = add(startingValue, 10); +let multipliedValue = multiply(addedValue, 2); +let goodCode = format(multipliedValue); /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. From e1c0f03cfffe329416b8c5d6ba0166cf1c72f235 Mon Sep 17 00:00:00 2001 From: Cecilia Date: Thu, 26 Nov 2020 14:07:55 +0000 Subject: [PATCH 5/8] Completed magic ball exercise --- extra/3-magic-8-ball.js | 72 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/extra/3-magic-8-ball.js b/extra/3-magic-8-ball.js index edb75fe65..46bf95866 100644 --- a/extra/3-magic-8-ball.js +++ b/extra/3-magic-8-ball.js @@ -42,19 +42,87 @@ My sources say no. Outlook not so good. Very doubtful. */ - +let answers = [ + {"content": "It is certain.", + "type": "very positive" + }, + {"content": "It is decidedly so.", + "type": "very positive" + }, + {"content": "Without a doubt.", + "type": "very positive" + }, + {"content": "Yes - definitely.", + "type": "very positive" + }, + {"content": "You may rely on it.", + "type": "very positive" + }, + {"content": "As I see it, yes.", + "type": "positive" + }, + {"content": "Most likely.", + "type": "positive" + }, + {"content": "Outlook good.", + "type": "positive" + }, + {"content": "Yes.", + "type": "positive" + }, + {"content": "Signs point to yes.", + "type": "positive" + }, + {"content": "Reply hazy, try again.", + "type": "negative" + }, + {"content": "Ask again later.", + "type": "negative" + }, + {"content": "Better not tell you now.", + "type": "negative" + }, + {"content": "Cannot predict now.", + "type": "negative" + }, + {"content": "Concentrate and ask again.", + "type": "negative" + }, + {"content": "Don't count on it.", + "type": "very negative" + }, + {"content": "My reply is no.", + "type": "very negative" + }, + {"content": "My sources say no.", + "type": "very negative" + }, + {"content": "Outlook not so good.", + "type": "very negative" + }, + {"content": "Very doubtful.", + "type": "very negative" + } +] // This should log "The ball has shaken!" // and return the answer. function shakeBall() { + let randomAnswer = Math.floor(Math.random() * 20); + console.log("The ball has shaken!") + return answers[randomAnswer].content; } - // This function should say whether the answer it is given is // - very positive // - positive // - negative // - very negative // This function should expect to be called with any value which was returned by the shakeBall function. + function checkAnswer(answer) { + var result = answers.filter(obj => { + return obj.content === answer + }) + return result[0].type; } /* ======= TESTS - DO NOT MODIFY ===== From dd996e69c92ac012f48a14de56f895f2d688a798 Mon Sep 17 00:00:00 2001 From: Cecilia Date: Sun, 6 Dec 2020 09:35:10 +0000 Subject: [PATCH 6/8] Fixed exercise G --- exercises/G-numbers/exercise.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index ef423ed0e..e5252027e 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -2,6 +2,6 @@ var numberOfStudents = 15; var numberOfMentors = 8; -console.log("Number of students: ",numberOfStudents); -console.log("Number of mentors: ", numberOfMentors); -console.log("Total number of students and mentors: ", numberOfMentors + numberOfStudents); +console.log("Number of students: " + numberOfStudents); +console.log("Number of mentors: " + numberOfMentors); +console.log("Total number of students and mentors: " + (numberOfMentors + numberOfStudents)); From 888ed54144b4a8b9bd5637a4c15c064aff1f0d39 Mon Sep 17 00:00:00 2001 From: Cecilia Date: Sun, 6 Dec 2020 09:37:12 +0000 Subject: [PATCH 7/8] Fixed exercise I --- exercises/I-floats/exercise.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index 2621cb68a..73dc2222f 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,5 +1,5 @@ var numberOfStudents = 15; var numberOfMentors = 8; -console.log("Percentage students:", Math.round(numberOfStudents/(numberOfStudents + numberOfMentors)*100)+"%"); -console.log("Percentage mentors:", Math.round(numberOfMentors/(numberOfStudents + numberOfMentors)*100)+"%"); \ No newline at end of file +console.log("Percentage students: " + Math.round(numberOfStudents/(numberOfStudents + numberOfMentors)*100)+"%"); +console.log("Percentage mentors: " + Math.round(numberOfMentors/(numberOfStudents + numberOfMentors)*100)+"%"); \ No newline at end of file From e17d6b424014189b9541f6a27cd1fcb73d8e6841 Mon Sep 17 00:00:00 2001 From: Cecilia Date: Sun, 6 Dec 2020 09:49:46 +0000 Subject: [PATCH 8/8] Changed var to const or let --- exercises/C-variables/exercise.js | 2 +- exercises/D-strings/exercise.js | 2 +- exercises/E-strings-concatenation/exercise.js | 6 +++--- exercises/F-strings-methods/exercise.js | 2 +- exercises/G-numbers/exercise.js | 4 ++-- exercises/I-floats/exercise.js | 4 ++-- exercises/J-functions/exercise.js | 5 ++++- exercises/J-functions/exercise2.js | 2 +- exercises/K-functions-parameters/exercise.js | 2 +- exercises/K-functions-parameters/exercise2.js | 2 +- exercises/K-functions-parameters/exercise3.js | 2 +- exercises/K-functions-parameters/exercise4.js | 2 +- exercises/L-functions-nested/exercise.js | 8 ++++---- exercises/L-functions-nested/exercise2.js | 10 +++++----- extra/3-magic-8-ball.js | 2 +- 15 files changed, 29 insertions(+), 26 deletions(-) diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index 628a44964..c2925e716 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,5 +1,5 @@ // Start by creating a variable `greeting` -var greeting = "Hello world"; +const greeting = "Hello world"; console.log(greeting); console.log(greeting); diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 7d54e9903..e4017fe0d 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,5 +1,5 @@ // Start by creating a variable `message` -var message = "This is a string"; +const message = "This is a string"; console.log(message); console.log(typeof message); diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index e7994ed5d..3d25e22e2 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,7 +1,7 @@ // Start by creating a variable `message` -var greetingStart = "Hello, my name is "; -var name = "Cecilia"; +let greetingStart = "Hello, my name is "; +let name = "Cecilia"; -var greeting = greetingStart + name; +let greeting = greetingStart + name; console.log(greeting); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 8279fe57c..be0666203 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,4 +1,4 @@ // Start by creating a variable `message` -var name = "Cecilia" +const name = "Cecilia" console.log("My name is " + name + " and my name is " + name.length + " characters long"); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index e5252027e..0e721eb3f 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1,6 +1,6 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` -var numberOfStudents = 15; -var numberOfMentors = 8; +const numberOfStudents = 15; +const numberOfMentors = 8; console.log("Number of students: " + numberOfStudents); console.log("Number of mentors: " + numberOfMentors); diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index 73dc2222f..dbc18a946 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,5 +1,5 @@ -var numberOfStudents = 15; -var numberOfMentors = 8; +const numberOfStudents = 15; +const numberOfMentors = 8; console.log("Percentage students: " + Math.round(numberOfStudents/(numberOfStudents + numberOfMentors)*100)+"%"); console.log("Percentage mentors: " + Math.round(numberOfMentors/(numberOfStudents + numberOfMentors)*100)+"%"); \ No newline at end of file diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index e9ba2f0ef..59ae60365 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -3,6 +3,9 @@ function halve(number) { return number/2; } -var result = halve(12); +let result = halve(12); + +let result1 = halve(15); console.log(result); +console.log(result1); diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 6d216ffc6..1a4ac1ee7 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -3,6 +3,6 @@ function triple(number) { return number*3; } -var result = triple(12); +let result = triple(12); console.log(result); diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index e37f89d44..f05588aee 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -5,6 +5,6 @@ function multiply(a,b) { } // Assign the result of calling the function the variable `result` -var result = multiply(3, 4); +const result = multiply(3, 4); console.log(result); diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index 02a698a36..a70898192 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -3,6 +3,6 @@ function divide(a, b) { return a/b; } -var result = divide(3, 4); +const result = divide(3, 4); console.log(result); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 6de0f0538..05624ee16 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -3,6 +3,6 @@ function createGreeting(greet) { return "Hello, my name is " + greet; } -var greeting = createGreeting("Daniel"); +const greeting = createGreeting("Daniel"); console.log(greeting); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 4e573f041..852e1111e 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -3,6 +3,6 @@ function addition(a,b) { return a + b; } // Call the function and assign to a variable `sum` -var sum = addition(13, 124); +let sum = addition(13, 124); console.log(sum); diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index 0fb873021..e64158c96 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -1,5 +1,5 @@ -var students = { "type": "students", "number": 15}; -var mentors = { "type": "mentors", "number": 8}; +let students = { "type": "students", "number": 15}; +let mentors = { "type": "mentors", "number": 8}; function calculatePercentage(a,b) { return Math.round(a.number / (a.number + b.number) * 100); @@ -9,8 +9,8 @@ function createMessage(cat1, cat2) { return "Percentage " + cat1.type + ": " + calculatePercentage(cat1, cat2) + "%"; } -var percentageOfStudents = createMessage(students, mentors); -var percentageOfMentors = createMessage(mentors, students); +let percentageOfStudents = createMessage(students, mentors); +let percentageOfMentors = createMessage(mentors, students); console.log(percentageOfStudents); console.log(percentageOfMentors); \ No newline at end of file diff --git a/exercises/L-functions-nested/exercise2.js b/exercises/L-functions-nested/exercise2.js index 54059d6d6..f2d923d4f 100644 --- a/exercises/L-functions-nested/exercise2.js +++ b/exercises/L-functions-nested/exercise2.js @@ -1,8 +1,8 @@ -var mentor1 = "Daniel"; -var mentor2 = "Irina"; -var mentor3 = "Mimi"; -var mentor4 = "Rob"; -var mentor5 = "Yohannes"; +let mentor1 = "Daniel"; +let mentor2 = "Irina"; +let mentor3 = "Mimi"; +let mentor4 = "Rob"; +let mentor5 = "Yohannes"; function shoutName(name) { return name.toUpperCase(); diff --git a/extra/3-magic-8-ball.js b/extra/3-magic-8-ball.js index 46bf95866..b6c1285fa 100644 --- a/extra/3-magic-8-ball.js +++ b/extra/3-magic-8-ball.js @@ -119,7 +119,7 @@ function shakeBall() { // This function should expect to be called with any value which was returned by the shakeBall function. function checkAnswer(answer) { - var result = answers.filter(obj => { + let result = answers.filter(obj => { return obj.content === answer }) return result[0].type;