Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// 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": [
"<node_internals>/**"
],
"program":"${file}"
}
]
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.formatOnPaste": true,
"editor.formatOnSave": true
}
2 changes: 1 addition & 1 deletion exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log("Hello world");
console.log("Hello world i am learning java");
4 changes: 3 additions & 1 deletion exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Start by creating a variable `greeting`

var greeting = "Hello word ";
console.log(greeting);
console.log(greeting);
console.log(greeting);
5 changes: 3 additions & 2 deletions exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Start by creating a variable `message`
var message = "this is a string";
var messagetype = typeof message; // Start by creating a variable `message`

console.log(message);
console.log(messagetype);
7 changes: 4 additions & 3 deletions exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Start by creating a variable `message`

console.log(message);
var greetingStart = "Hello"; // Start by creating a variable `message`
var name = " my name is Houda";
var greeting = greetingStart + name;
console.log(greeting);
9 changes: 8 additions & 1 deletion exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
// Start by creating a variable `message`

console.log(message);
var message = "my name is Houda and my name is";

var name = "Houda";
var nameLength = name.length;

var characters = "characters long";
var greeting = message + " " + nameLength + " " + characters;
console.log(greeting);
9 changes: 9 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
var numberOfStudents = 15;
var numberOfMentors = 8;
var sum = numberOfStudents + numberOfMentors;
console.log(sum);

var numberOfStudents = 15;
var numberOfMentors = 8;
var sum = (numberOfStudents = numberOfMentors);
console.log(sum);
10 changes: 10 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
var sum = numberOfMentors + numberOfStudents;
console.log(sum);
var studentPercentage = (numberOfStudents / 23) * 100;
console.log(studentPercentage);
var roughstudent = Math.round(studentPercentage);
console.log(roughstudent);
var mentorPercentage = (numberOfMentors / 23) * 100;
console.log(mentorPercentage);
var roughmentors = Math.round(mentorPercentage);
console.log(roughmentors);
11 changes: 9 additions & 2 deletions exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
function halve(number) {
// complete the function here
return number / 2;
}

var result = halve(12);
let result = halve(12);

console.log(result);

function trimWord(word) {
return word.trim();
}

let words = " vertyhuhnb ";
console.log(words);
2 changes: 1 addition & 1 deletion exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function triple(number) {
// complete function here
return number * number * number;
}

var result = triple(12);
Expand Down
4 changes: 2 additions & 2 deletions exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Complete the function so that it takes input parameters
function multiply() {
// Calculate the result of the function and return it
function multiply(a, b) {
return a * b;
}

// Assign the result of calling the function the variable `result`
Expand Down
4 changes: 3 additions & 1 deletion exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Declare your function first
function divide(a, b) {
return a / b;
}

var result = divide(3, 4);

Expand Down
4 changes: 3 additions & 1 deletion exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Write your function here
function createGreeting(inputname) {
return "Hello my name is" + " " + inputname;
}

var greeting = createGreeting("Daniel");

Expand Down
6 changes: 4 additions & 2 deletions exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Declare your function first
function sum(a, b) {
return a + b;
}

// Call the function and assign to a variable `sum`
var sum = sum(124, 13);

console.log(sum);
6 changes: 5 additions & 1 deletion exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// Declare your function here
function createLongGreeting(inputname, age) {
return (
"Hello my name is" + " " + inputname + " and Iam " + age + " " + "years old"
);
}

const greeting = createLongGreeting("Daniel", 30);

Expand Down
7 changes: 7 additions & 0 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";

function toUpperCase(mentor) {
return mentor.toUpperCase();
}

let mentor = toUpperCase(mentor2);
console.log(toUpperCase);
7 changes: 5 additions & 2 deletions extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

function convertToUSD() {}

function convertToUSD(£) {
return 1.4 * convertToUSD(£);
}
var convert = convertToUSD(£50);
console.log(convert);
/*
CURRENCY CONVERSION
===================
Expand Down
6 changes: 4 additions & 2 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
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;

}

Expand Down
20 changes: 13 additions & 7 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
// 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";
var number = addNumbers(3, 4, 6);
console.log(number);

function getTotal(a, b) {
total = a ++ b;

return "The total is total";
function introduceMe(name, age) {
return "Hello, my name is " + name + " and I am " + age + " " + "years old";
}
var introduce = ("Sonjide", 27);
console.log(introduceMe);

function getTotal(a, b) {
let total = a + b;
return "The total is " + total;
}
var get = (23, 5);
console.log(getTotal);
/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
16 changes: 11 additions & 5 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
// 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();
}

let words = " CodeYourFuture ";
console.log(words);

function getStringLength(word) {
return "word".length();
return word.length;
}
var get = "Turtles";
console.log(get);

function multiply(a, b, c) {
a * b * c;
return;
return a * b * c;
}
var mult = (2, 3, 4);
console.log(mult);

/*
===================================================
Expand All @@ -24,7 +30,7 @@ To run the tests for just this one file, type `npm test -- --testPathPattern 2-l
===================================================
*/

test("trimWord trims leading and trailing whitespace", () => {
test("trimWord trims leading and trailing ", () => {
expect(trimWord(" CodeYourFuture ")).toEqual("CodeYourFuture");
});

Expand Down
12 changes: 10 additions & 2 deletions mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
Sales tax is 20% of the price of the product.
*/

function calculateSalesTax() {}
function calculateSalesTax(a) {
return a + (a * 20) / 100;
}

var vax = 15;
console.log(vax);
/*
CURRENCY FORMATTING
===================
Expand All @@ -17,7 +21,11 @@ function calculateSalesTax() {}
Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
*/

function addTaxAndFormatCurrency() {}
function addTaxAndFormatCurrency(a) {
return "£" + a + (a * 20) / 100;
}
var tax = 17.5;
console.log(math.round(tax));

/*
===================================================
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"url": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1/issues"
},
"jest": {
"setupFilesAfterEnv": ["jest-extended"]
"setupFilesAfterEnv": [
"jest-extended"
]
},
"homepage": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1#readme",
"devDependencies": {
Expand Down