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.
2 changes: 1 addition & 1 deletion exercises/B-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Inside of `exercise.js` there's a line of code that will print "Hello world!".
### 1. Run the program

- Open a terminal window
- Change directory to this folder (`cd exercises/B-hello-world`) - assuming you're at the project root
- Change directory to this folder (`cd B-hello-world`)
- Run the program using node (`node exercise.js`)

### 2. Experiment
Expand Down
3 changes: 2 additions & 1 deletion exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
console.log("Hello world");
console.log("hello world, I am learning to be a developer!");
console.log("hello world, I am learning everyday");
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`
const greeting = "Hello world";

console.log(greeting);
console.log(greeting);
console.log(greeting);
3 changes: 3 additions & 0 deletions exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Start by creating a variable `message`
const message = "This is a string";
const messageType = typeof message;

console.log(message);
console.log(messageType);
5 changes: 5 additions & 0 deletions 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`

const greetingStart = "Hello, my name is ";
const myName = "Harsheek";

const message = greetingStart + myName;

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

console.log(message);
const message = "Harsheek";

console.log(
`My name is ${message} and my name is ${message.length} characters long`
);
4 changes: 4 additions & 0 deletions exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const name = " Daniel ";

const message = `My name is ${name.trim()} and my name is ${
name.trim().length
} characters long`;

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

const numberOfStudents = 15;
const numberOfMentors = 8;

console.log(`Number of students: ${numberOfStudents}`);

console.log(`Number of mentors: ${numberOfMentors}`);

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

console.log(
`Percentage students: ${Math.round(
(numberOfStudents / (numberOfMentors + numberOfStudents)) * 100
)}%`
);

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

var result = halve(12);
Expand Down
1 change: 1 addition & 0 deletions exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function triple(number) {
// complete function here
return number * 3;
}

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

// Assign the result of calling the function the variable `result`
Expand Down
4 changes: 4 additions & 0 deletions exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Declare your function first

function divide(a, b) {
return a / b;
}

var result = divide(3, 4);

console.log(result);
4 changes: 4 additions & 0 deletions exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Write your function here

function createGreeting(name) {
return `Hello, my name is ${name}`;
}

var greeting = createGreeting("Daniel");

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 sumNumbers(a, b) {
return a + b;
}

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

console.log(sum);
4 changes: 4 additions & 0 deletions exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// 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);

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

function logShoutyGreeting(name) {
let uppercaseName = makeUppercase(name);

return `HELLO ${uppercaseName}`;
}

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

console.log(logShoutyGreeting(mentor1));
console.log(logShoutyGreeting(mentor2));
console.log(logShoutyGreeting(mentor3));
console.log(logShoutyGreeting(mentor4));
console.log(logShoutyGreeting(mentor5));
10 changes: 7 additions & 3 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 CONVERSION
Expand All @@ -15,12 +17,14 @@ 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) {
return parseFloat((price * 0.99 * 5.7).toFixed(2));
}

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

To run the tests for just this one file, type `npm test -- --testPathPattern 1-currency-conversion` into your terminal
To run these tests type `npm run extraTo run the tests for just this one file, type `npm run extra-tests -- --testPathPattern 1-syntax-errors` into your terminal
(Reminder: You must have run `npm install` one time before this will work!)
*/

Expand Down
24 changes: 11 additions & 13 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
- one that multiplies 2 numbers together
- one that formats a number so it's returned as a string with a £ sign before it (e.g. 20 -> £20)

2. Using the variable startingValue as input, perform the following operations using your functions all
on one line (assign the result to the variable badCode):
2. Using the variable startingValue as input, perform the following operations using your functions all on one line (assign the result to the variable badCode):
- add 10 to startingValue
- multiply the result by 2
- format it
Expand All @@ -16,31 +15,30 @@
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;
}

function format() {

function format(number) {
return `£${number}`;
}

const startingValue = 2;
const startingValue = (2 + 10) * 2;

// Why can this code be seen as bad practice? Comment your answer.
let badCode =
let badCode = format(startingValue);

/* BETTER PRACTICE */

let goodCode =

let goodCode = format(multiply(add(2, 10), 2));
/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.

To run the tests for just this one file, type `npm test -- --testPathPattern 2-piping` into your terminal
To run these tests type `npm run extraTo run the tests for just this one file, type `npm run extra-tests -- --testPathPattern 2-piping` into your terminal
(Reminder: You must have run `npm install` one time before this will work!)
*/

Expand Down
61 changes: 55 additions & 6 deletions extra/3-magic-8-ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
and have different levels of positivity or negativity.

Below are the possible answers:

## Very positive
It is certain.
It is decidedly so.
Expand Down Expand Up @@ -43,10 +43,50 @@
Very doubtful.
*/

// This should log "The ball has shaken!"
// and return the answer.
const veryPositive = [
"It is certain.",
"It is decidedly so.",
"Without a doubt.",
"Yes - definitely.",
"You may rely on it.",
];

const positive = [
"As I see it, yes.",
"Most likely.",
"Outlook good.",
"Yes.",
"Signs point to yes.",
];

const negative = [
"Reply hazy, try again.",
"Ask again later.",
"Better not tell you now.",
"Cannot predict now.",
"Concentrate and ask again.",
];

const veryNegative = [
"Don't count on it.",
"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
const allAnswers = [
...veryPositive,
...positive,
...negative,
...veryNegative,
];
return allAnswers[Math.round(Math.random() * allAnswers.length)];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thank you so much for your resubmission and I should have found out it much earlier! Nice and quality work as before. Refer to line 80, the function should log "The ball has shaken" to console when it is called

}

/*
Expand All @@ -55,11 +95,18 @@ function shakeBall() {
- positive
- negative
- very negative

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 (veryPositive.includes(answer)) {
return "very positive";
} else if (positive.includes(answer)) {
return "positive";
} else if (negative.includes(answer)) {
return "negative";
} else {
return "very negative";
}
}

/*
Expand All @@ -68,7 +115,7 @@ function checkAnswer(answer) {

There are some Tests in this file that will help you work out if your code is working.

To run the tests for just this one file, type `npm test -- --testPathPattern 3-magic-8-ball` into your terminal
To run these tests type `npm run extraTo run the tests for just this one file, type `npm run extra-tests -- --testPathPattern 3-magic-8-ball` into your terminal

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 need to change the package.json if you want to run all tests. See Marina's work for the changes on the 3-magic-8-ball.js and package.json

(Reminder: You must have run `npm install` one time before this will work!)
==================================
*/
Expand Down Expand Up @@ -101,7 +148,9 @@ test("magic 8 ball returns different values each time", () => {
);
}

let seenPositivities = new Set(Array.from(seenAnswers.values()).map(checkAnswer));
let seenPositivities = new Set(
Array.from(seenAnswers.values()).map(checkAnswer)
);
if (seenPositivities.size < 2) {
throw Error(
"Expected to random answers with different positivities each time shakeBall was called, but always got the same one"
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;

return "The total is total";
return `The total is ${total}`;
}

/*
Expand Down
7 changes: 3 additions & 4 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -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;
}

/*
Expand Down
Loading