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
5 changes: 4 additions & 1 deletion exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
console.log("Hello world");
console.log(" Hello World. I just started learning JavaScript");
console.log(" Hello World. I just started learning JavaScript");
console.log(" Hello World. I just started learning JavaScript");
console.log(5);
3 changes: 3 additions & 0 deletions exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Start by creating a variable `greeting`
var greeting = "Hello world";

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

var message = "This is a string";
var messageType = typeof message;

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

console.log(message);
let message = "Hi everyone,nice to meet you, I am ";

let name = "Murat";

let myMessage = message + name;

console.log(myMessage);
11 changes: 11 additions & 0 deletions exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
// Start by creating a variable `message`
let message1 = "My name is ";

let message2 = " and my name is ";

let message3 = " characters long";

let name = "Murat";

let message = message1 + name + message2 + name.length + message3;

// below method seems easier
// let message = `My name is ${name} and my name is ${name.length} characters long`;
console.log(message);
7 changes: 6 additions & 1 deletion exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
const name = " Daniel ";
const name = " Murat ";

//assigning trimmed name to a new variable
let trimmedName = name.trim();

let message = `My name is ${trimmedName} and my name is ${trimmedName.length} characters long`;

console.log(message);
12 changes: 12 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`

let numberOfStudents = 15;

let numberOfMentors = 8;

let totalNumbers = numberOfStudents + numberOfMentors;

console.log("Number of students: " + numberOfStudents);

console.log("Number of mentors: " + numberOfMentors);

console.log("Total number of students and mentors: " + totalNumbers);
7 changes: 7 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
var numberOfStudents = 15;
var numberOfMentors = 8;

let perOfStudents = numberOfStudents / (numberOfStudents + numberOfMentors);
let perOfMentors = numberOfMentors / (numberOfMentors + numberOfStudents);

console.log(`Percentage students : ${Math.round(perOfStudents * 100)} %`);

console.log(`Percentage mentors : ${Math.round(perOfMentors * 100)} %`);
4 changes: 2 additions & 2 deletions exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function halve(number) {
// complete the function here
return number / 2;
}

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

console.log(result);
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 * 3;
}

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(num1, num2) {
return num1 * num2;
}

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

var result = divide(3, 4);

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

var greeting = createGreeting("Daniel");
var greeting = createGreeting("Murat");

console.log(greeting);
4 changes: 4 additions & 0 deletions exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Declare your function first
function adder(num1, num2) {
return num1 + num2;
}

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

console.log(sum);
5 changes: 4 additions & 1 deletion exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// 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);
const greeting = createLongGreeting("Murat", 30);

console.log(greeting);
26 changes: 26 additions & 0 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,29 @@ var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";

// In `exercise2.js` you have been provided with the names of some mentors. Write a program that logs a shouty greeting to each one.
// - Your program should include a function that spells their name in uppercase, and a function that creates a shouty greeting.
// - Log each greeting to the console.

// ## Expected result

// ```
// HELLO DANIEL
// HELLO IRINA
// HELLO MIMI
// HELLO ROB
// HELLO YOHANNES

function changeNameToUpperCase(name) {
return name.toUpperCase();
}

function greeting(name) {
console.log(`HELLO ${changeNameToUpperCase(name)}`);
}
greeting(mentor1);
greeting(mentor2);
greeting(mentor3);
greeting(mentor4);
greeting(mentor5);
9 changes: 7 additions & 2 deletions extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
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
Expand All @@ -15,7 +17,10 @@ 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) {
let newPrice = (price * 99) / 100;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: You could do price * 0.9;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Kara, you have spotted every detail.I appreciate your support.

return newPrice * 5.7;
}

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
55 changes: 30 additions & 25 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,54 @@
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(num) {
return `£${num}`;
}

const startingValue = 2
const startingValue = 2;

// Why can this code be seen as bad practice? Comment your answer.
let badCode =
// it is really hard to track functions
let badCode = format(multiply(add(startingValue, 10), 2));

/* BETTER PRACTICE */

let goodCode =
let addedNumbers = add(startingValue, 10);
let multipliedNumber = multiply(addedNumbers, 2);
let formattedNumber = format(multipliedNumber);
let goodCode = formattedNumber;

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.

To run these tests type `node 2-piping.js` into your terminal
*/

const util = require('util');
const util = require("util");

function test(test_name, actual, expected) {
let status;
if (actual === expected) {
status = "PASSED";
} else {
status = `FAILED: expected: ${util.inspect(expected)} but your code returned: ${util.inspect(actual)}`;
}

console.log(`${test_name}: ${status}`);
let status;
if (actual === expected) {
status = "PASSED";
} else {
status = `FAILED: expected: ${util.inspect(
expected
)} but your code returned: ${util.inspect(actual)}`;
}

console.log(`${test_name}: ${status}`);
}

test('add function - case 1 works', add(1,3), 4)
test('add function - case 2 works', add(2.4,5), 7.4)
test('multiply function works', multiply(2,3), 6)
test('format function works', format(16), "£16")
test('badCode variable correctly assigned', badCode, "£24")
test('goodCode variable correctly assigned', goodCode, "£24")
test("add function - case 1 works", add(1, 3), 4);
test("add function - case 2 works", add(2.4, 5), 7.4);
test("multiply function works", multiply(2, 3), 6);
test("format function works", format(16), "£16");
test("badCode variable correctly assigned", badCode, "£24");
test("goodCode variable correctly assigned", goodCode, "£24");
50 changes: 47 additions & 3 deletions extra/3-magic-8-ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,43 @@

// This should log "The ball has shaken!"
// and return the answer.
let answers = [
[
"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.",
],
[
"Don't 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!");
let randomNumber1 = Math.floor(Math.random() * 4);
let randomNumber2 = Math.floor(Math.random() * 5);
let message = answers[randomNumber1][randomNumber2];
// console.log(message);
return message;
}

/*
Expand All @@ -59,9 +94,18 @@ 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
if (answers[0].includes(answer)) {
return "very positive";
} else if (answers[1].includes(answer)) {
return "positive";
} else if (answers[2].includes(answer)) {
return "negative";
} else if (answers[3].includes(answer)) {
return "very negative";
}
}

// let message = checkAnswer(shakeBall());
// console.log(message);
/*
==================================
======= TESTS - DO NOT MODIFY =====
Expand Down
Loading