From 4d46a49cce430e93a9041b83fe61d0079f736774 Mon Sep 17 00:00:00 2001 From: Timur Abdullaev <85526272+Timur85@users.noreply.github.com> Date: Thu, 2 Sep 2021 00:01:34 +0100 Subject: [PATCH 1/2] West Midlands 3 - Timur Abdullaev - JS Core 1 - Week 1 I'm apologize for completing homework so late. --- exercises/B-hello-world/exercise.js | 3 +++ exercises/C-variables/exercise.js | 4 +++- exercises/D-strings/exercise.js | 4 +++- exercises/E-strings-concatenation/exercise.js | 6 ++++-- exercises/F-strings-methods/exercise.js | 9 ++++++++- exercises/F-strings-methods/exercise2.js | 2 +- exercises/G-numbers/exercise.js | 6 ++++++ exercises/I-floats/exercise.js | 6 ++++++ exercises/J-functions/exercise.js | 2 +- exercises/J-functions/exercise2.js | 2 +- exercises/K-functions-parameters/exercise.js | 3 +-- exercises/K-functions-parameters/exercise2.js | 4 +++- exercises/K-functions-parameters/exercise3.js | 4 +++- exercises/K-functions-parameters/exercise4.js | 6 ++++-- exercises/K-functions-parameters/exercise5.js | 7 +++++-- exercises/L-functions-nested/exercise.js | 10 ++++++++++ 16 files changed, 62 insertions(+), 16 deletions(-) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..2ebb41e64 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,4 @@ console.log("Hello world"); +console.log("I just started learning JavaScript!"); +// console.log (without quote marks); +console.log(5); diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..3244c32f2 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..6aa689519 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 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..40fd415d4 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); +var greetingStart = "Hello, my name is "; +var myName = "Timur"; +var greeting = `${greetingStart}${myName}`; +console.log(greeting); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..9864ded48 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,10 @@ // Start by creating a variable `message` - +var name = "Timur"; +var nameLength = name.length; +var message = + "My name is " + + `${name}` + + " and my name is " + + `${nameLength}` + + " characters long "; console.log(message); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..c50400331 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,3 @@ const name = " Daniel "; - +var message = name.trim(); console.log(message); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..421b639a1 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; +var sum = numberOfStudents + numberOfMentors; +console.log(`Number of students: ${numberOfStudents}`); +console.log(`Number of mentors: ${numberOfMentors}`); +console.log(`Total numnber of students and mentors: ${sum}`); diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..a85d7f8ef 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,8 @@ var numberOfStudents = 15; var numberOfMentors = 8; +var sum = numberOfStudents + numberOfMentors; +var pStudents = Math.round((numberOfStudents * 100) / sum); +var pMentors = Math.round((numberOfMentors * 100) / sum); + +console.log(`Percentage students: ${pStudents}%`); +console.log(`Percentage mentors: ${pMentors}%`); diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..e7278f7bd 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,5 +1,5 @@ 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..95ef62512 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..5e9d50040 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,9 +1,8 @@ // Complete the function so that it takes input parameters function multiply() { - // Calculate the result of the function and return it + return 3 * 4; } -// Assign the result of calling the function the variable `result` var result = multiply(3, 4); console.log(result); diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..ac8792cf0 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,4 +1,6 @@ -// Declare your function first +function divide() { + return 3 / 4; +} var result = divide(3, 4); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..bed59804f 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; +} var greeting = createGreeting("Daniel"); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..1a6a732ec 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(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..41791c2cb 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,8 @@ -// Declare your function here - +function createLongGreeting(name, age) { + return "Hello, my name is " + name + " and I'm " + age + " years old"; +} +var name = "Daniel"; +var age = 30; 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..737b9b592 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -1,5 +1,15 @@ +function greeting(name) { + return "HELLO " + name.toUpperCase(); +} + 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 25d3fea1c83939a6b04c4b907d15053b3ab9b980 Mon Sep 17 00:00:00 2001 From: Timur Abdullaev <85526272+Timur85@users.noreply.github.com> Date: Thu, 2 Sep 2021 00:23:11 +0100 Subject: [PATCH 2/2] West Midlands 3 - Timur Abdullaev - JS Core 1 - Week 1 --- mandatory/1-syntax-errors.js | 11 ++++++----- mandatory/2-logic-error.js | 7 +++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..98360ac6b 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; } /* diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9cca7603b..db8e788b8 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 getStringLength(word) { - return "word".length(); + return word.length(); } function multiply(a, b, c) { - a * b * c; - return; + return a * b * c; } /*