diff --git a/exercises/B-hello-world/README.md b/exercises/B-hello-world/README.md index 27282c4af..85cd05bc6 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? Face with SyntaxError(missing ) after argument list) +- What happens when you console.log() just a number without quotes? Face with SyntaxError(missing ) after argument list) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..ae6f53018 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1 @@ -console.log("Hello world"); +console.log("Hello World. I just started learning JavaScript!" ); diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..1bab81a4f 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `greeting` - +let greeting="Hi Leila" console.log(greeting); +console.log(greeting); +console.log(greeting); \ No newline at end of file diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..07334b5cd 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` - +let message="this is a string" +let messageType=typeof message; console.log(message); +console.log(messageType); +// console.log(message + " "+ typeof message); diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..6c583f835 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` - -console.log(message); +let greetingSentence ="Hi my name is"; +let name="Leila"; +let greeting =greetingSentence +" " + name; +console.log(greeting); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..0f2978cee 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` - -console.log(message); +let name="Leila"; +let message=name.length; +console.log("My name is"+" "+name + " "+ "and my name is"+" " + message+" "+ "character long."); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..2541d2045 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); +const message=name.length; +console.log("My name is" + " " + name.trim() + " " + "and my name is" + " " + message + " " +"character long."); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..34bfd982f 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,5 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +const numberOfStudents=10; +const numberOfMentors=7; +const sum=numberOfStudents+numberOfMentors; +console.log("Total number of students and mentors:" + sum); \ No newline at end of file diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..ebbd200c1 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,8 @@ var numberOfStudents = 15; var numberOfMentors = 8; +var total = numberOfMentors + numberOfStudents; +let studentPerc = Math.round((numberOfMentors / total) * 100); +let mentorPerc = Math.round((numberOfStudents / total) * 100); + +console.log("Percent of student :" + " " + studentPerc + "%"); +console.log("Percent of mentor :" + " " + mentorPerc + "%"); 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..e7c787d04 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(a, b) { + return a / b; +} 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..d1728ae72 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,5 +1,7 @@ // Write your function here - +function createGreeting(name){ + return "Hello, My name is " + name; +} var greeting = createGreeting("Daniel"); console.log(greeting); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..56b4cc834 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,7 @@ // Declare your function first - +function add(a,b){ + return a+b; +} // Call the function and assign to a variable `sum` - +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..f399b6bf6 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..60bab6ebd 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -1,5 +1,26 @@ + +var greet="HELLO"; var mentor1 = "Daniel"; var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; + + +function upperCase(name){ + + return name.toUpperCase(); +} +function showName(greet,name){ + return greet +" "+ upperCase(name); +} +let result1=showName(greet,mentor1); +let result2 = showName(greet, mentor2); +let result3 = showName(greet, mentor3); +let result4 = showName(greet, mentor4); +let result5 = showName(greet, mentor5); +console.log(result1); +console.log(result2); +console.log(result3); +console.log(result4); +console.log(result5); \ No newline at end of file diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index 75b3c6aab..b80492a6a 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) { + price *=1.4; + return price; +} /* CURRENCY CONVERSION @@ -15,7 +18,11 @@ 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) { + price*=5.7; + total=(price-(price*1/100)).toFixed(2); + return +total; +} /* ======= 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 b4f8c4c1b..61ea616cf 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -16,26 +16,29 @@ the final result to the variable goodCode */ -function add() { - +function add(num1,num2) { + return num1+num2; } -function multiply() { - +function multiply(num1,num2) { + return num1*num2; } -function format() { - +function format(number) { + return `£${number.toString()}` } const startingValue = 2; // Why can this code be seen as bad practice? Comment your answer. -let badCode = +let badCode = `£${(startingValue+10)*2}` + -/* BETTER PRACTICE */ -let goodCode = +/* BETTER PRACTICE */ +const sum=startingValue+10; +const result=sum*2; +let goodCode =`£${result}`; /* ======= 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/3-magic-8-ball.js b/extra/3-magic-8-ball.js index 46f65f928..f597682ee 100644 --- a/extra/3-magic-8-ball.js +++ b/extra/3-magic-8-ball.js @@ -45,10 +45,40 @@ // This should log "The ball has shaken!" // and return the answer. +let fixAnswer = [ + "It is certain.", //0 + "It is decidedly so.", //1 + "Without a doubt.", //2 + "Yes - definitely.", //3 + "You may rely on it.", //4-very positive + "As I see it, yes.", //5 + "Most likely.", //6 + "Outlook good.", //7 + "Yes.", //8 + "Signs point to yes.", //9-positive + "Reply hazy, try again.", //10 + "Ask again later.", //11 + "Better not tell you now.", //12 + "Cannot predict now.", //13 + "Concentrate and ask again.", //14-negetive + " Don't count on it.", //15 + "My reply is no.", //16 + "My sources say no.", //17 + "Outlook not so good.", //18 + " Very doubtful.", //19-very negetive +]; + + function shakeBall() { //Write your code in here + console.log("The ball has shaken!"); + randomNumber = Math.floor(Math.random() * fixAnswer.length); + result =fixAnswer[randomNumber]; + return result; } + + /* This function should say whether the answer it is given is - very positive @@ -58,10 +88,25 @@ function shakeBall() { 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 -} + function checkAnswer(answer) { + //Write your code in here + let ballPredict = fixAnswer.indexOf(answer); + if (ballPredict <= 4) { + answer = "very positive"; + } else if (ballPredict <= 9) { + answer = "positive"; + } else if (ballPredict <= 14) { + answer = "negative"; + } else if (ballPredict <= 19) { + answer = "very negative"; + } else answer = "Something broken"; + + return answer; + } + + + /* ================================== ======= TESTS - DO NOT MODIFY ===== @@ -82,12 +127,16 @@ test("whole magic 8 ball sequence", () => { expect(consoleLogSpy).toHaveBeenCalledTimes(1); expect(consoleLogSpy).toHaveBeenLastCalledWith("The ball has shaken!"); - expect(checkAnswer(answer)).toBeOneOf([ - "very positive", + // expect(checkAnswer(answer)).toBeOneOf([ + // "very positive", + // "positive", + // "negative", + // "very negative", + // ]); + expect(["very positive", "positive", "negative", - "very negative", - ]); + "very negative"]).toContain(checkAnswer(answer)) }); test("magic 8 ball returns different values each time", () => { diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..19e701d88 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,16 +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; + total = a + b; - return "The total is total"; + return "The total is " +total; } /* diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9cca7603b..4f41a4e4f 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,16 +1,22 @@ // 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(); } +word = " CodeYourFuture "; +word = " CodeYourFuture teaches coding "; function getStringLength(word) { - return "word".length(); + + return word.length; } + word = getStringLength("A wild sentence appeared!"); + word = getStringLength("Turtle"); ; function multiply(a, b, c) { - a * b * c; - return; + const result= a * b * c; + return result; } /* diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..b113cbd07 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,17 +1,24 @@ // Add comments to explain what this function does. You're meant to use Google! + +/* This function creat an integer random number(by multiplying decimal random number by ten)*/ function getRandomNumber() { return Math.random() * 10; } // Add comments to explain what this function does. You're meant to use Google! + +/*This function concat two words which will be pass to the function as an argument +for example if word1="ali" and word="reza" the result of this function will be "alireza"*/ function combine2Words(word1, word2) { return word1.concat(word2); } 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; } +firstWord="code"; +secondWord="your"; +thirdWord="future"; /* =================================================== diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..5e8fda32a 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -4,8 +4,13 @@ A business requires a program that calculates how much the price of a product is including sales tax Sales tax is 20% of the price of the product. */ + + -function calculateSalesTax() {} +function calculateSalesTax(price) { + const saleTax = (price * 20) / 100; + return price + saleTax; +} /* CURRENCY FORMATTING @@ -17,7 +22,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) { + + return `£${calculateSalesTax(price).toFixed(2)}`; +} /* ===================================================