diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..a66d882 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "pwa-node", + "request": "launch", + "name": "Launch Program", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}\\week-1\\1-exercises\\B-hello-world\\exercise.js" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7a3e4f4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "editor.formatOnSave": true, + "editor.formatOnPaste": true, + "launch": { + + } +} \ No newline at end of file diff --git a/week-1/0-freecodecamp/Screenshot (434).png b/week-1/0-freecodecamp/Screenshot (434).png new file mode 100644 index 0000000..e12dd58 Binary files /dev/null and b/week-1/0-freecodecamp/Screenshot (434).png differ diff --git a/week-1/1-exercises/A-setup-ide/README.md b/week-1/1-exercises/A-setup-ide/README.md index 1412871..c46a226 100644 --- a/week-1/1-exercises/A-setup-ide/README.md +++ b/week-1/1-exercises/A-setup-ide/README.md @@ -11,3 +11,6 @@ There are some tools that will help you to write code. One of these, [Prettier]( * 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 + + +I installed the prettier and Enabled the formatting on save. \ No newline at end of file diff --git a/week-1/1-exercises/B-hello-world/README.md b/week-1/1-exercises/B-hello-world/README.md index 2ac9fe5..66a9148 100644 --- a/week-1/1-exercises/B-hello-world/README.md +++ b/week-1/1-exercises/B-hello-world/README.md @@ -15,4 +15,6 @@ 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? + If we pass string without quotes it gives a syntax error. * What happens when you console.log() just a number without quotes? + The number is displayed on the console. diff --git a/week-1/1-exercises/B-hello-world/exercise.js b/week-1/1-exercises/B-hello-world/exercise.js index b179ee9..9c382b3 100644 --- a/week-1/1-exercises/B-hello-world/exercise.js +++ b/week-1/1-exercises/B-hello-world/exercise.js @@ -1 +1,3 @@ -console.log("Hello world"); +console.log("Hello world, I am very excited about learning JavaScript."); +console.log("My name is Ali Haider"); +console.log(1234); diff --git a/week-1/1-exercises/C-variables/exercise.js b/week-1/1-exercises/C-variables/exercise.js index a6bbb97..3244c32 100644 --- a/week-1/1-exercises/C-variables/exercise.js +++ b/week-1/1-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/week-1/1-exercises/D-strings/exercise.js b/week-1/1-exercises/D-strings/exercise.js index 2cffa6a..eae819e 100644 --- a/week-1/1-exercises/D-strings/exercise.js +++ b/week-1/1-exercises/D-strings/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` - +var message = "This is a string"; +var messageType = typeof message ; console.log(message); +console.log(messageType); \ No newline at end of file diff --git a/week-1/1-exercises/E-strings-concatenation/exercise.js b/week-1/1-exercises/E-strings-concatenation/exercise.js index 2cffa6a..6e2f022 100644 --- a/week-1/1-exercises/E-strings-concatenation/exercise.js +++ b/week-1/1-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 name = "Daniel"; +var greeting = greetingStart + name; +console.log(greeting); diff --git a/week-1/1-exercises/F-strings-methods/exercise.js b/week-1/1-exercises/F-strings-methods/exercise.js index 2cffa6a..5a5f20d 100644 --- a/week-1/1-exercises/F-strings-methods/exercise.js +++ b/week-1/1-exercises/F-strings-methods/exercise.js @@ -1,3 +1,9 @@ // Start by creating a variable `message` +var name = "Ali Haider"; +var nameLength = name.length; +var greeting = "My name is "; +var greeting2 = " and my name is "; +var message = " characters long"; +var totalMessage = greeting + name + greeting2+ nameLength + message; +console.log(totalMessage); -console.log(message); diff --git a/week-1/1-exercises/F-strings-methods/exercise2.js b/week-1/1-exercises/F-strings-methods/exercise2.js index b4b4694..a0907ba 100644 --- a/week-1/1-exercises/F-strings-methods/exercise2.js +++ b/week-1/1-exercises/F-strings-methods/exercise2.js @@ -1,3 +1,8 @@ -const name = " Daniel "; - -console.log(message); +const name = " Ali Haider "; +var orignalName = name.trim(); +var orignalNameLength = orignalName.length; +var greeting = "My name is "; +var greeting2 = " and my name is "; +var message = " characters long"; +var totalMessage = greeting + orignalName + greeting2 + orignalNameLength+ message; +console.log(totalMessage); diff --git a/week-1/1-exercises/G-numbers/exercise.js b/week-1/1-exercises/G-numbers/exercise.js index 49e7bc0..02a582c 100644 --- a/week-1/1-exercises/G-numbers/exercise.js +++ b/week-1/1-exercises/G-numbers/exercise.js @@ -1 +1,9 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +var numberofStudents = 15; +var numberofMentors = 8; + +total = numberofStudents+ numberofMentors; + +console.log("Number of students: " + numberofStudents); +console.log("Number of mentors: " + numberofMentors); +console.log("Total number of students and mentors: "+ total); \ No newline at end of file diff --git a/week-1/1-exercises/I-floats/README.md b/week-1/1-exercises/I-floats/README.md index e7c3999..56e2f96 100644 --- a/week-1/1-exercises/I-floats/README.md +++ b/week-1/1-exercises/I-floats/README.md @@ -20,4 +20,4 @@ var roughAge = Math.round(preciseAge); // 30 ``` Percentage students: 65% Percentage mentors: 35% -``` +``` \ No newline at end of file diff --git a/week-1/1-exercises/I-floats/exercise.js b/week-1/1-exercises/I-floats/exercise.js index a5bbcd8..b62292f 100644 --- a/week-1/1-exercises/I-floats/exercise.js +++ b/week-1/1-exercises/I-floats/exercise.js @@ -1,2 +1,10 @@ var numberOfStudents = 15; var numberOfMentors = 8; + +total = numberOfStudents + numberOfMentors; + +var percentageOfStudents = Math.round((numberOfStudents/total) * 100); +var percentageOfMentors = Math.round((numberOfMentors / total) * 100); + +console.log("Percentage students: "+ percentageOfStudents+ "%"); +console.log("Percentage mentors: " + percentageOfMentors+ "%"); diff --git a/week-1/1-exercises/J-functions/exercise.js b/week-1/1-exercises/J-functions/exercise.js index 0ae5850..033cc24 100644 --- a/week-1/1-exercises/J-functions/exercise.js +++ b/week-1/1-exercises/J-functions/exercise.js @@ -1,5 +1,7 @@ function halve(number) { // complete the function here + var divide = number / 2; + return divide; } var result = halve(12); diff --git a/week-1/1-exercises/J-functions/exercise2.js b/week-1/1-exercises/J-functions/exercise2.js index 82ef5e7..c38e3a0 100644 --- a/week-1/1-exercises/J-functions/exercise2.js +++ b/week-1/1-exercises/J-functions/exercise2.js @@ -1,5 +1,7 @@ function triple(number) { // complete function here + var multiply = number * 3; + return multiply; } var result = triple(12); diff --git a/week-1/1-exercises/K-functions-parameters/exercise.js b/week-1/1-exercises/K-functions-parameters/exercise.js index 8d5db5e..ce0abea 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise.js +++ b/week-1/1-exercises/K-functions-parameters/exercise.js @@ -1,6 +1,8 @@ // Complete the function so that it takes input parameters -function multiply() { +function multiply(num1 , num2) { // Calculate the result of the function and return it + var result = num1 * num2; + return result; } // Assign the result of calling the function the variable `result` diff --git a/week-1/1-exercises/K-functions-parameters/exercise2.js b/week-1/1-exercises/K-functions-parameters/exercise2.js index db7a890..395b6bd 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise2.js +++ b/week-1/1-exercises/K-functions-parameters/exercise2.js @@ -1,5 +1,8 @@ // Declare your function first - +function divide(num1,num2){ + var result = num1/num2 ; + return result; +} var result = divide(3, 4); console.log(result); diff --git a/week-1/1-exercises/K-functions-parameters/exercise3.js b/week-1/1-exercises/K-functions-parameters/exercise3.js index 537e9f4..96dd5a2 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise3.js +++ b/week-1/1-exercises/K-functions-parameters/exercise3.js @@ -1,5 +1,8 @@ // Write your function here - +function createGreeting(name){ + var message = "Hello, my name is "+ name; + return message; +} var greeting = createGreeting("Daniel"); console.log(greeting); diff --git a/week-1/1-exercises/K-functions-parameters/exercise4.js b/week-1/1-exercises/K-functions-parameters/exercise4.js index 7ab4458..4394588 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise4.js +++ b/week-1/1-exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,8 @@ // Declare your function first - + function add( num1 , num2){ + var addition = num1 + num2 ; + return addition; + } // Call the function and assign to a variable `sum` - +var sum = add(13,124); console.log(sum); diff --git a/week-1/1-exercises/K-functions-parameters/exercise5.js b/week-1/1-exercises/K-functions-parameters/exercise5.js index 7c5bcd6..8cb6d28 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise5.js +++ b/week-1/1-exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,11 @@ // Declare your function here - +function createLongGreeting(name , age){ + var message = "Hello, my name is "; + var message2 = " and I'm "; + var message3 = " years old"; + var finalMessage = message + name + message2+ age + message3; + return finalMessage; +} const greeting = createLongGreeting("Daniel", 30); console.log(greeting); diff --git a/week-1/1-exercises/L-functions-nested/exercise.js b/week-1/1-exercises/L-functions-nested/exercise.js index a5d3774..4988edb 100644 --- a/week-1/1-exercises/L-functions-nested/exercise.js +++ b/week-1/1-exercises/L-functions-nested/exercise.js @@ -1,5 +1,13 @@ -var mentor1 = "Daniel"; -var mentor2 = "Irina"; -var mentor3 = "Mimi"; -var mentor4 = "Rob"; -var mentor5 = "Yohannes"; +function Percentage(numberOfStudents, numberOfMentors){ + var total = numberOfStudents + numberOfMentors; + var percentageOfStudents = Math.round((numberOfStudents / total) * 100); + var percentageOfMentors = Math.round((numberOfMentors / total) * 100); + return percentageOfMentors,percentageOfStudents; +} +function message(){ + console.log("Percentage students: " + Percentage(15,8) + "%"); + console.log("Percentage mentors: " + Percentage(8,15) + "%"); + +} + +message(); \ No newline at end of file diff --git a/week-1/1-exercises/L-functions-nested/exercise2.js b/week-1/1-exercises/L-functions-nested/exercise2.js new file mode 100644 index 0000000..62788f1 --- /dev/null +++ b/week-1/1-exercises/L-functions-nested/exercise2.js @@ -0,0 +1,23 @@ +var mentor1 = "Daniel"; +var mentor2 = "Irina"; +var mentor3 = "Mimi"; +var mentor4 = "Rob"; +var mentor5 = "Yohannes"; + +function captilize(str){ + + str.toUpperCase(); + return str.toUpperCase();; +} + +function greetings(){ + // captilize(mentor1, mentor2, mentor3, mentor4, mentor5); + var msg = "HELLO "; + console.log( msg + captilize(mentor1)); + console.log(msg + captilize(mentor2)); + console.log(msg + captilize(mentor3)); + console.log(msg + captilize(mentor4)); + console.log(msg + captilize(mentor5)); + +} +greetings(); diff --git a/week-1/2-mandatory/1-syntax-errors.js b/week-1/2-mandatory/1-syntax-errors.js index 6910f28..8f52920 100644 --- a/week-1/2-mandatory/1-syntax-errors.js +++ b/week-1/2-mandatory/1-syntax-errors.js @@ -2,18 +2,22 @@ // 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 getAddition(a, b) { - total = a ++ b + total = a + b; // Use string interpolation here - return "The total is %{total}" + return `The total is ${total}`; +} +function getRemainder (a,b){ + + return "The remainder is "+ a % b; } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-1/2-mandatory/2-logic-error.js b/week-1/2-mandatory/2-logic-error.js index 1e0a9d4..f64f61a 100644 --- a/week-1/2-mandatory/2-logic-error.js +++ b/week-1/2-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; } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/week-1/2-mandatory/3-function-output.js b/week-1/2-mandatory/3-function-output.js index bbb88a2..7e2a11b 100644 --- a/week-1/2-mandatory/3-function-output.js +++ b/week-1/2-mandatory/3-function-output.js @@ -1,9 +1,14 @@ // Add comments to explain what this function does. You're meant to use Google! +// This function generate a random number between a range of 0 to 10. +// Math.random() generate a floating point number between a range of 0 to 1. +// In which 0 is inclusive and 1 is exclusive. function getNumber() { return Math.random() * 10; } // Add comments to explain what this function does. You're meant to use Google! +// concat() method is used to combine or join two strings. +// In this function w2 is added to the infront of w1. function s(w1, w2) { return w1.concat(w2); } @@ -11,6 +16,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 to expect in return + return firstWord+" "+secondWord+" "+thirdWord } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/week-1/2-mandatory/4-tax.js b/week-1/2-mandatory/4-tax.js index 6b84208..829a61a 100644 --- a/week-1/2-mandatory/4-tax.js +++ b/week-1/2-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/100*20) + price; +} /* CURRENCY FORMATTING @@ -17,7 +19,9 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function formatCurrency() {} +function formatCurrency(price) { + return "£"+calculateSalesTax(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.