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
Binary file added .DS_Store
Binary file not shown.
Binary file added exercises/.DS_Store
Binary file not shown.
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(555);
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 World"
console.log(greeting);
console.log(greeting);
console.log(greeting);
7 changes: 6 additions & 1 deletion exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Start by creating a variable `message`
// var message = "This is a string";
// var messageType = typeof message;

console.log(message);
// console.log(messageType);

var message = "Terminal still scares me";
console.log(typeof message);
7 changes: 6 additions & 1 deletion exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Start by creating a variable `message`
var message = "Hello, my name is ";
var firstName = "Gulnihal";

console.log(message);
var greeting = message + firstName;


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When leaving gaps between lines of code, it's best to go for no more than one line at a time to make things easier to read 🙂

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

var firstName = "Gulnihal";

var firstNameLength = firstName.length;


console.log(firstNameLength);

var message = "My name is Gulnihal and my name is 8 characters long"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here you could concatenate the message variable using the other two variables, either with a plus operator + or through interpolation. So could have
var message = "My name is " + firstName + " and my name is " + firstNameLength + " characters long"
or
var message = `My name is ${firstName} and my name is ${firstNameLength} characters long`

console.log(message);

var noSpaceMessage = message.trim;
console.log(noSpaceMessage);
7 changes: 4 additions & 3 deletions exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const name = " Daniel ";

console.log(message);
const name = " Gulnihal ";
var message = "My name is Gulnihal and my name is 8 characters long"
var noSpace = message.trim;
console.log(noSpace);
4 changes: 4 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
var numberOfStudents =30;
var numberOfMentors = 16;
var totalNumberOfStudentsAndMentors = numberOfStudents + numberOfMentors;
console.log(totalNumberOfStudentsAndMentors);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You could also use string concatenation here to log it in this format

Number of students: 15
Number of mentors: 8
Total number of students and mentors: 23

15 changes: 15 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
var numberOfStudents = 15;
var numberOfMentors = 8;


// var preciseAge = 30.612437;
// var roughAge = Math.round(preciseAge);
// console.log(roughAge);

var proportionStudents = (numberOfStudents / (numberOfStudents + numberOfMentors)) *100;
console.log(proportionStudents);
var roughProportionStudents = Math.round(proportionStudents);
console.log(roughProportionStudents);

var proportionMentors = (numberOfMentors / (numberOfStudents + numberOfMentors)) *100;
console.log(proportionMentors);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Instead of using numberOfStudents + numberOfMentors twice here, you could assign it to a variable like before, so totalNumberOfStudentsAndMentors and reference that instead, it'll make the statement more concise 🙂

var roughProportionMentors = Math.round(proportionMentors);
console.log(roughProportionMentors);
2 changes: 1 addition & 1 deletion exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function halve(number) {
// complete the function here
return number / 2; // complete the function here
}

var result = halve(12);
Expand Down
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; // complete function here
}

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; // Calculate the result of the function and return it
}

// 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 (num1, num2) {
return num1 / num2;
}// Declare your function first

var result = divide(3, 4);

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

var greeting = createGreeting("Daniel");
Expand Down
5 changes: 4 additions & 1 deletion exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
function add(num1, num2){
return num1 + num2;
}
// Declare your function first

// Call the function and assign to a variable `sum`

var sum = add(13, 124);
console.log(sum);
3 changes: 3 additions & 0 deletions exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
function createLongGreeting (name, age){
return "Hello, my name is " + name + " and I'm " +age + " years old"
}
// Declare your function here

const greeting = createLongGreeting("Daniel", 30);
Expand Down
18 changes: 18 additions & 0 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,21 @@ var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";

function nameUpperCase(mentor) {
return mentor.toUpperCase();
}
function greeting(name){
let message = "HELLO " + nameUpperCase(name);
return message;
}

console.log(greeting(mentor1));

console.log(greeting(mentor2));

console.log(greeting(mentor3));

console.log(greeting(mentor4));

console.log(greeting(mentor5));
11 changes: 9 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,12 @@ 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 BrlToP = parseFloat((price *(99/100) * 5.7).toFixed(2));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Because this variable won't change after being assigned it's better to use const here

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Also to make it easier to know what the numbers are for, it is better to assign them to variables. So we could have

  const transactionFee = 0.01;
  const exchangeRate = 5.7;
  const amountAfterFee = amountInPounds * (1 - transactionFee);

This is just to help avoid 'magic numbers' https://levelup.gitconnected.com/magic-numbers-820d2d570cc5


return BrlToP;

}

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
19 changes: 10 additions & 9 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,27 @@
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;
}

const startingValue = 2;

// Why can this code be seen as bad practice? Comment your answer.
let badCode =
// Why can this code be seen as bad practice? Comment your answer.
// bacause: lots of parantheses, and there are already mathematical symbols to do these operations.
let badCode = format(multiply((add(startingValue, 10)), 2));

/* BETTER PRACTICE */

let goodCode =
let goodCode = "£" + ((startingValue+10)*2);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It's actually the other way round here, it's better practice to use the functions, as it gives less room for error. However, you could make it more readable, because as you said it looks quite crowded. You could assign the output of each function to a variable and then reference that, it'd make it easier to read. For example:

const startingValueAddTen = add(startingValue, 10);
const multipliedByTwo = multiply(startingValueAddTen, 2);
const formattedValue = format(multipliedByTwo);


/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
81 changes: 51 additions & 30 deletions extra/3-magic-8-ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,45 @@
and have different levels of positivity or negativity.

Below are the possible answers:

## Very positive
It is certain.
It is decidedly so.
Without a doubt.
Yes - definitely.
You may rely on it.

## Positive
As I see it, yes.
Most likely.
Outlook good.
Yes.
Signs point to yes.

## Negative
Reply hazy, try again.
Ask again later.
Better not tell you now.
Cannot predict now.
Concentrate and ask again.

## Very negative
Don't count on it.
My reply is no.
My sources say no.
Outlook not so good.
Very doubtful.
*/

// ## Very positive
let answers = [
"It is certain.",
"It is decidedly so.",
"Without a doubt.",
"Yes - definitely.",
"You may rely on it.",

// ## Positive
"As I see it, yes.",
"Most likely.",
"Outlook good.",
"Yes.",
"Signs point to yes.",

// ## Negative
"Reply hazy, try again.",
"Ask again later.",
"Better not tell you now.",
"Cannot predict now.",
"Concentrate and ask again.",

// ## Very negative
"Don't count on it.",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You could also have 4 different array variables here, veryPositive, positive, negative, and veryNegative and concatenating these in the answers one

"My reply is no.",
"My sources say no.",
"Outlook not so good.",
"Very doubtful."
];


// This should log "The ball has shaken!"
// and return the answer.
function shakeBall() {
//Write your code in here
console.log("The ball has shaken!")
var index = Math.floor(Math.random()*answers.length);
return answers[index];
}

/*
Expand All @@ -59,7 +64,23 @@ 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
let index = answers.indexOf(answer);

return index <5 ? "very positive"
:index <10 ? "positive"
:index <15 ? "negative"
: "very negative";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Very nice use of the ternary operator here 🙂

// if (index <5){
// return "very positive";
// } else if (index >= 5 && index <10) {
// return "positive";
// } else if (index >= 10 && index <15) {
// return "negative";
// } else {
// return "very negative";
// }
//Write your code in here
}

/*
Expand Down
11 changes: 6 additions & 5 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This also needs a const 🙂

return "The total is total";
return "The total is " + total;
}

/*
Expand Down
10 changes: 5 additions & 5 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -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();
function getStringLength(word) {
return word.length;
}

function multiply(a, b, c) {
a * b * c;
return;

return a * b * c;
}

/*
Expand Down
11 changes: 6 additions & 5 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Add comments to explain what this function does. You're meant to use Google!
function getRandomNumber() {
function getRandomNumber() { //gets random numbers
return Math.random() * 10;
}

// Add comments to explain what this function does. You're meant to use Google!
function combine2Words(word1, word2) {
function combine2Words(word1, word2) { //combine two words without space between them
return word1.concat(word2);
}

function concatenate(firstWord, secondWord, thirdWord) {
return firstWord.concat(secondWord, thirdWord);
// Write the body of this function to concatenate three words together.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can add spaces as separate strings here, for example firstWord.concat(" ", secondWord, " ", thirdWord);

// Look at the test case below to understand what this function is expected to return.
}
Expand All @@ -25,13 +26,13 @@ To run the tests for just this one file, type `npm test -- --testPathPattern 3-f
*/

test("concatenate example #1", () => {
expect(concatenate("code", "your", "future")).toEqual("code your future");
expect(concatenate("code ", "your ", "future")).toEqual("code your future");
});

test("concatenate example #2", () => {
expect(concatenate("I", "like", "pizza")).toEqual("I like pizza");
expect(concatenate("I ", "like ", "pizza")).toEqual("I like pizza");
});

test("concatenate doesn't only accept strings", () => {
expect(concatenate("I", "am", 13)).toEqual("I am 13");
expect(concatenate("I ", "am ", 13)).toEqual("I am 13");
});
Loading