From 80dbafce18584f09c9bbcf401c2b8935caeda410 Mon Sep 17 00:00:00 2001 From: ademalagoz <65690057+ademalagoz@users.noreply.github.com> Date: Thu, 21 Jan 2021 02:03:15 +0000 Subject: [PATCH 1/5] Half of Exercises --- exercises/A-setup-ide/README.md | 15 +++++++++------ exercises/B-hello-world/README.md | 4 ++-- exercises/B-hello-world/exercise.js | 5 ++++- exercises/C-variables/exercise.js | 4 +++- exercises/D-strings/exercise.js | 9 +++++++++ exercises/E-strings-concatenation/exercise.js | 5 ++++- exercises/F-strings-methods/exercise.js | 6 +++++- exercises/F-strings-methods/exercise2.js | 6 ++++-- 8 files changed, 40 insertions(+), 14 deletions(-) diff --git a/exercises/A-setup-ide/README.md b/exercises/A-setup-ide/README.md index 1412871b6..b08a75aad 100644 --- a/exercises/A-setup-ide/README.md +++ b/exercises/A-setup-ide/README.md @@ -2,12 +2,15 @@ There are some tools that will help you to write code. One of these, [Prettier]( ### 1. Install prettier -* In Visual Studio open the extensions panel (see https://code.visualstudio.com/docs/editor/extension-gallery#_browse-and-install-extensions) -* Search for `Prettier - Code formatter` -* Click install on the top result +- In Visual Studio open the extensions panel (see https://code.visualstudio.com/docs/editor/extension-gallery#_browse-and-install-extensions) +- Search for `Prettier - Code formatter` +- Click install on the top result ### 2. Enable formatting on save -* In Visual Studio open the settings file (see https://code.visualstudio.com/docs/getstarted/settings#_creating-user-and-workspace-settings) -* Search for `editor format` -* Set `editor.formatOnSave` and `editor.formatOnPaste` to true +- In Visual Studio open the settings file (see https://code.visualstudio.com/docs/getstarted/settings#_creating-user-and-workspace-settings) +- Search for `editor format` +- Set `editor.formatOnSave` and `editor.formatOnPaste` to true + +xxxx +All done for WSL-Ubuntu version diff --git a/exercises/B-hello-world/README.md b/exercises/B-hello-world/README.md index a7b891d56..7c26e967e 100644 --- a/exercises/B-hello-world/README.md +++ b/exercises/B-hello-world/README.md @@ -14,5 +14,5 @@ Inside of `exercise.js` there's a line of code that will print "Hello world!". * 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? +* What happens when you get rid of the quote marks?>>>>SyntaxError: missing ) after argument list +* What happens when you console.log() just a number without quotes?>>>>Without quotes it's just a number but with quotes it's string diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..0728a0409 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(2021) +console.log('2021') diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..d0d1cdf61 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,5 @@ // 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..abadf27ed 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,12 @@ // Start by creating a variable `message` +var message = 'This is a string'; +var messageType = typeof message; +var messageOther = 'Here is an other string'; +var messageType = typeof messageOther; +var messageAnother = 'There is an another string'; +var messageType = typeof messageAnother; console.log(message); +console.log(messageOther); +console.log(messageAnother); + diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..e92df87e9 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` +var greetingStart ='Hello, My name is '; +var name ='Adem'; -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..40f8c81f8 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` +const name ='Adem'; +const greetings ='My name is '+ name +' and my name is '+name.length +' characters long'; +console.log(greetings); + + -console.log(message); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..059d766d7 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,5 @@ -const name = " Daniel "; +const name =' Adem '; +const NoWhiteSpace = name.trim(); +const greetings ='My name is '+ NoWhiteSpace +' and my name is '+ NoWhiteSpace.length +' characters long'; +console.log(greetings); -console.log(message); From e4df4fc6e41e28176d45ef0ff780e33749028d28 Mon Sep 17 00:00:00 2001 From: ademalagoz <65690057+ademalagoz@users.noreply.github.com> Date: Fri, 22 Jan 2021 02:01:57 +0000 Subject: [PATCH 2/5] Finished the Exercises --- exercises/G-numbers/README.md | 4 ++-- exercises/G-numbers/exercise.js | 12 ++++++++++ exercises/I-floats/exercise.js | 6 +++++ exercises/J-functions/exercise.js | 11 ++++++++-- exercises/J-functions/exercise2.js | 2 +- exercises/K-functions-parameters/exercise.js | 3 ++- exercises/K-functions-parameters/exercise2.js | 5 ++++- exercises/K-functions-parameters/exercise3.js | 4 +++- exercises/K-functions-parameters/exercise4.js | 6 +++-- exercises/K-functions-parameters/exercise5.js | 11 +++++++++- exercises/L-functions-nested/exercise.js | 19 +++++++++++----- exercises/L-functions-nested/exercise2.js | 22 +++++++++++++++++++ 12 files changed, 89 insertions(+), 16 deletions(-) create mode 100644 exercises/L-functions-nested/exercise2.js diff --git a/exercises/G-numbers/README.md b/exercises/G-numbers/README.md index 4c6f45a41..76a79dab2 100644 --- a/exercises/G-numbers/README.md +++ b/exercises/G-numbers/README.md @@ -17,8 +17,8 @@ var difference = 10 - 2; // 8 ## Exercise -* Create two variables `numberOfStudents` and `numberOfMentors` -* Log a message that displays the total number of students and mentors +- Create two variables `numberOfStudents` and `numberOfMentors` +- Log a message that displays the total number of students and mentors ## Expected result diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..a98aa499e 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,13 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +var numberOfStudents =15; +var numberOfMentors =8; +var sum = numberOfStudents + numberOfMentors; +// var product =numberOfStudents * numberOfMentors; +// var quotient=numberOfStudents / numberOfMentors; +// var difference =numberOfStudents - numberOfMentors +console.log('Number of students:'+ numberOfStudents); +console.log('Number of mentors:'+ numberOfMentors); +console.log('Total number of students and mentors:'+ sum); +// console.log(product); +// console.log(quotient); +// console.log(difference); \ No newline at end of file diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..f512c4523 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,8 @@ var numberOfStudents = 15; var numberOfMentors = 8; +const total =numberOfStudents + numberOfMentors; +let percentageOfStudents = Math.round(numberOfStudents/total*100); +let percentageOfMentors = Math.round(numberOfMentors/total*100); +console.log('Percentage Of Students:' + percentageOfStudents +'%'); +console.log('Percentage Of Mentors:' + percentageOfMentors +'%'); + diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..011261f4f 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,7 +1,14 @@ function halve(number) { - // complete the function here + return number/2; } var result = halve(12); - +var result2 = halve(14); +var result3 = halve(16); +var result4 = halve(18); +var result5 = halve(20); console.log(result); +console.log(result2); +console.log(result3); +console.log(result4); +console.log(result5); 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..5be5c19c2 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(num1,num2) { // Calculate the result of the function and return it + 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..d3f7bb3a9 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(num1,num2){ +return num1/num2; + +}// Declare your function first var result = divide(3, 4); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..230d0fd4d 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,4 +1,6 @@ -// Write your function here +function createGreeting(name){ + return 'Hello, my name is ' + name; +}// Write your function here var greeting = createGreeting("Daniel"); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..462ba7b4b 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,7 @@ // Declare your function first - +function total(num1,num2){ + return num1+num2; +} // Call the function and assign to a variable `sum` - +var sum =total(13,124) console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..a39dbea40 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,14 @@ // Declare your function here - +function createLongGreeting(name,age){ + return 'Hello, my name is '+name +' I am '+ age + ' years old' +} const greeting = createLongGreeting("Daniel", 30); console.log(greeting); + +// * Write a function that takes a name (a string) and an age (a number) and returns a greeting (a string) + +// ## Expected result + +// ``` +// Hello, my name is Daniel and I'm 30 years old \ No newline at end of file diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..dbf20620a 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -1,5 +1,14 @@ -var mentor1 = "Daniel"; -var mentor2 = "Irina"; -var mentor3 = "Mimi"; -var mentor4 = "Rob"; -var mentor5 = "Yohannes"; + +function percentage(num,total){ + return Math.round(num/total*100); + +}; + +function result(num,total){ + const equal = percentage(num,total); + return equal; + +} +console.log('percentage students: '+ result(15,23)+'%'); +console.log('percentage mentors: '+ result(8,23)+'%'); + diff --git a/exercises/L-functions-nested/exercise2.js b/exercises/L-functions-nested/exercise2.js new file mode 100644 index 000000000..fc43c1bb9 --- /dev/null +++ b/exercises/L-functions-nested/exercise2.js @@ -0,0 +1,22 @@ +var mentor1 = "Daniel"; +var mentor2 = "Irina"; +var mentor3 = "Mimi"; +var mentor4 = "Rob"; +var mentor5 = "Yohannes"; + +function upperName(name){ + + return name.toUpperCase() +}; + +function shoutyGreeting(name){ +var message = 'HELLO' + upperName(name); +return message; + +}; + +console.log(shoutyGreeting(' Daniel')); +console.log(shoutyGreeting(' Irina')); +console.log(shoutyGreeting(' Mimi')); +console.log(shoutyGreeting(' Rob')); +console.log(shoutyGreeting(' Yohannes')); \ No newline at end of file From 9cfc6914f8065d4942e3551d4331ad7e08cabaa4 Mon Sep 17 00:00:00 2001 From: ademalagoz <65690057+ademalagoz@users.noreply.github.com> Date: Sat, 23 Jan 2021 00:40:50 +0000 Subject: [PATCH 3/5] Finished Mandatory --- exercises/B-hello-world/exercise.js | 4 +-- exercises/F-strings-methods/exercise2.js | 4 +-- exercises/K-functions-parameters/exercise4.js | 2 +- mandatory/1-syntax-errors.js | 28 +++++++++++-------- mandatory/2-logic-error.js | 8 +++--- mandatory/3-function-output.js | 5 ++++ mandatory/4-tax.js | 11 ++++++-- 7 files changed, 39 insertions(+), 23 deletions(-) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index 0728a0409..12ceda5f0 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1,4 +1,4 @@ console.log('Hello World.I just started learning JavaScript!'); -console.log(2021) -console.log('2021') +console.log(2021); +console.log('2021'); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index 059d766d7..88175fc87 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,5 +1,5 @@ const name =' Adem '; -const NoWhiteSpace = name.trim(); -const greetings ='My name is '+ NoWhiteSpace +' and my name is '+ NoWhiteSpace.length +' characters long'; +const noWhiteSpace = name.trim(); +const greetings ='My name is '+ noWhiteSpace +' and my name is '+ noWhiteSpace.length +' characters long'; console.log(greetings); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 462ba7b4b..18506ae42 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -3,5 +3,5 @@ function total(num1,num2){ return num1+num2; } // Call the function and assign to a variable `sum` -var sum =total(13,124) +var sum =total(13,124); console.log(sum); diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index 0a21afd1b..fd187c227 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,28 +1,32 @@ // 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; } +// console.log(addNumbers(3, 4, 6)); -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"; +} +// console.log(introduceMe("Sonjide",27)); function getTotal(a, b) { - total = a ++ b; + var total = a + b; - return "The total is total" + return "The total is "+ total; } +// console.log(getTotal(23,5)); -/* -=================================================== -======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== +// /* +// =================================================== +// ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== -There are some Tests in this file that will help you work out if your code is working. +// There are some Tests in this file that will help you work out if your code is working. -To run these tests type `node 1-syntax-errors.js` into your terminal +// To run these tests type `node 1-syntax-errors.js` into your terminal -=================================================== -*/ +// =================================================== +// */ const util = require('util'); diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 3c578ad87..1429cacc3 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,16 +1,16 @@ // 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; + } /* diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index c9221a200..c4130448b 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,14 +1,19 @@ // Add comments to explain what this function does. You're meant to use Google! +//returns a random number between 0 (inclusive) and 1 (exclusive) and multiplies with 10 function getNumber() { return Math.random() * 10; } +// console.log(getNumber()); // Add comments to explain what this function does. You're meant to use Google! +//combines typed array with the new array. function s(w1, w2) { return w1.concat(w2); } +// console.log(s); function concatenate(firstWord, secondWord, thirdWord) { + return firstWord.concat(" " + 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. } diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index c9e41c691..492393bf7 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,12 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(price) { + + var decimalSellingPrice = calculateSalesTax(price).toFixed(2); + return "£"+ decimalSellingPrice; + +} /* =================================================== From 95b326fa6e2956229caa3bbbb3fe033f95de150c Mon Sep 17 00:00:00 2001 From: ademalagoz <65690057+ademalagoz@users.noreply.github.com> Date: Sat, 23 Jan 2021 01:27:21 +0000 Subject: [PATCH 4/5] Added Extra1-2 --- extra/1-currency-conversion.js | 9 +++++++-- extra/2-piping.js | 25 ++++++++++++++++++------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index 70a2fe863..aecb50ce8 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -5,7 +5,10 @@ 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 +18,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*5.7)*0.99; +} /* ======= 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..8192336b3 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -16,26 +16,37 @@ the final result to the variable goodCode */ -function add() { +function add(number1,number2) { + + + return number1+number2; } -function multiply() { - +function multiply(number1,number2) { + return number1*number2; } -function format() { +function format(number3) { + return "£"+number3; } const startingValue = 2 // Why can this code be seen as bad practice? Comment your answer. -let badCode = +//It's hard to read it +// - add 10 to startingValue +// - multiply the result by 2 +// - format it -/* BETTER PRACTICE */ -let goodCode = +let badCode = format(multiply(add(startingValue,10),2)); + +/* BETTER PRACTICE */ +let total =add(startingValue,10); +let product =multiply(total,2) +let goodCode = format(product); /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. From a57d3de8f53f9c34cb51498553401ec93f34c7c8 Mon Sep 17 00:00:00 2001 From: ademalagoz <65690057+ademalagoz@users.noreply.github.com> Date: Sat, 23 Jan 2021 23:37:00 +0000 Subject: [PATCH 5/5] Indentations fixed --- exercises/K-functions-parameters/exercise2.js | 2 +- exercises/K-functions-parameters/exercise5.js | 4 +- exercises/L-functions-nested/exercise2.js | 4 +- extra/1-currency-conversion.js | 2 +- extra/2-piping.js | 7 +- extra/3-magic-8-ball.js | 66 ++++++++++++++++--- 6 files changed, 65 insertions(+), 20 deletions(-) diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index d3f7bb3a9..e973665ee 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,5 +1,5 @@ function divide(num1,num2){ -return num1/num2; + return num1/num2; }// Declare your function first diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index a39dbea40..4efdc26b7 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,6 +1,6 @@ // Declare your function here -function createLongGreeting(name,age){ - return 'Hello, my name is '+name +' I am '+ age + ' years old' +function createLongGreeting(name , age){ + return 'Hello, my name is '+ name +' I am '+ age + ' years old' } const greeting = createLongGreeting("Daniel", 30); diff --git a/exercises/L-functions-nested/exercise2.js b/exercises/L-functions-nested/exercise2.js index fc43c1bb9..62c457b64 100644 --- a/exercises/L-functions-nested/exercise2.js +++ b/exercises/L-functions-nested/exercise2.js @@ -10,8 +10,8 @@ function upperName(name){ }; function shoutyGreeting(name){ -var message = 'HELLO' + upperName(name); -return message; + var message = 'HELLO' + upperName(name); + return message; }; diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index aecb50ce8..781078767 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -6,7 +6,7 @@ */ function convertToUSD(price) { -return price*1.4; + return price*1.4; } diff --git a/extra/2-piping.js b/extra/2-piping.js index 8192336b3..e502a4f0f 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -18,8 +18,7 @@ function add(number1,number2) { - - + return number1+number2; } @@ -44,8 +43,8 @@ const startingValue = 2 let badCode = format(multiply(add(startingValue,10),2)); /* BETTER PRACTICE */ -let total =add(startingValue,10); -let product =multiply(total,2) +let total = add(startingValue,10); +let product = multiply(total,2) let goodCode = format(product); /* ======= TESTS - DO NOT MODIFY ===== diff --git a/extra/3-magic-8-ball.js b/extra/3-magic-8-ball.js index e32182cfe..f5a614921 100644 --- a/extra/3-magic-8-ball.js +++ b/extra/3-magic-8-ball.js @@ -45,21 +45,67 @@ // This should log "The ball has shaken!" // and return the answer. + +var givenAnswers= [ + "It is certain", + "It is decidedly so.", + "Without a doubt.", + "Yes - definitely.", + "You may rely on it.", + + + "As I see it, yes.", + "Most likely.", + "Outlook good.", + "Yes.", + "Signs point to yes.", + + + "Reply hazy, try again.", + "Ask again later.", + "Better not tell you now.", + "Cannot predict now.", + "Concentrate and ask again.", + + + "Do not count on it.", + "My reply is no.", + "My sources say no.", + "Outlook not so good.", + "Very doubtful.", + ]; + + function shakeBall() { - //Write your code in here + console.log ("The ball has shaken!"); + var randomAnswer = Math.floor(Math.random()*19); + return givenAnswers[randomAnswer]; } -/* - This function should say whether the answer it is given is - - very positive - - positive - - negative - - very negative + + // *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. - This function should expect to be called with any value which was returned by the shakeBall function. -*/ function checkAnswer(answer) { - //Write your code in here + var xxxx + if (){ + return 'very positive' + } + else if (){ + return 'positive' + } + else if (){ + return 'negative' + } + else { + return 'very negative' + } + } /*