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
21 changes: 21 additions & 0 deletions exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@


//console.log(Hello world)
console.log("Hello world");

//Try to `console.log()` something different. For example, 'Hello World. I just started learning JavaScript!'
console.log("Hello World. I just started learning JavaScript!");


//What happens when you console.log() just a number without quotes?
//Terminal prints out a number.
console.log(80);


//Try to console.log() several things at once.
//Terminal prints out everything in one line.
console.log("I bought a shoes for £80", "Hello world", "I am curious to learn JS");


//What happens when you get rid of the quote marks?
//Terminal shows a syntax error.
console.log(I am curious to learn JS);
5 changes: 5 additions & 0 deletions exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Start by creating a variable `greeting`
//Add a variable `greeting` to exercise.js (make sure it comes _before_ the console.log
let greeting="Hello world!";

//Print your `greeting` to the console 3 times
console.log(greeting);
console.log(greeting);
console.log(greeting);
14 changes: 13 additions & 1 deletion exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
// Start by creating a variable `message`

console.log(message);
//Write a program that logs a message and its type
const number = 4;
let message = "Rahwa";
let text;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We use const if the content of the variable will not change, and if it changes we use let. So in this case all of them should have been const.

//Terminal shows a number
console.log(typeof number);

//Terminal shows a string
console.log(typeof message);

//Terminal shows undefined
console.log(typeof text);

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 also need to output the variables too not just their type. In the example, they missed it too.


4 changes: 4 additions & 0 deletions exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Start by creating a variable `message`
//Write a program that logs a message with a greeting and your name
let startGreeting = "Hi, my name is ";
let nameOfPerson="Rahwa";
let message = startGreeting + nameOfPerson;

console.log(message);
5 changes: 5 additions & 0 deletions exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Start by creating a variable `message`
//Log a message that includes the length of your name
let nameOfPerson = "Rahwa";
let nameOfPersonLength = nameOfPerson.length;
let message = `My name is ${nameOfPerson} and my name is ${nameOfPersonLength} character long.`;


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

//Log the same message using the variable, `name` provided
//Use the `.trim` method to remove the extra whitespace
const nameOfPerson = " Daniel ";
let message = nameOfPerson.trim();
console.log(message);
10 changes: 10 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`

//Create two variables `numberOfStudents` and `numberOfMentors`

let numberOfStudents = 15;
let numberOfMentors = 8;
let sum = numberOfStudents + numberOfMentors;

//Log a message that displays the total number of students and mentors

console.log(`The total number of students and mentors is ${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 @@

//Using the variables provided in the exercise calculate the percentage of mentors and students in the group

var numberOfStudents = 15;
var numberOfMentors = 8;
var total = numberOfStudents + numberOfMentors;
var percentageOfStudents = (Math.round(numberOfStudents/total * 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.

The outer () aren't needed.
It's best to leave spaces between mathematica ops.

Math.round(numberOfStudents / total * 100)

var percentageOfMentors = (Math.round(numberOfMentors / total * 100));


console.log (`percentage students:${percentageOfStudents}%`);
console.log(`percentage mentors:${percentageOfMentors}%`);
13 changes: 11 additions & 2 deletions exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@

//Complete the function in exercise.js so that it halves the input
function halve(number) {
// complete the function here
return number/2;
}

var result = halve(12);
//Try calling the function more than once with some different numbers
let resultOne = halve(12);
let resultTwo = halve(50);
let resultThree = halve(125);

console.log(resultOne);
console.log(resultTwo);
console.log(resultThree);

console.log(result);
10 changes: 7 additions & 3 deletions exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@

//Complete the function in exercise2.js so that it triples the input

function triple(number) {
// complete function here

return number * 3;
}
let resultOne = triple(12);

var result = triple(12);

console.log(result);
console.log(resultOne);
5 changes: 3 additions & 2 deletions exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// 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`
var result = multiply(3, 4);
let result = multiply(3, 4);

console.log(result);
6 changes: 4 additions & 2 deletions exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Declare your function first

var result = divide(3, 4);
function divide(a, b){
return a/b;
}
let result = divide(3, 4);

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

var greeting = createGreeting("Daniel");
function creatGreeting(nameOfPerson){
return `Hello, my name is ${nameOfPerson}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Indentations and spacing should be like this:

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

}
//calling the function
let greeting = creatGreeting("Daniel");

console.log(greeting);
8 changes: 7 additions & 1 deletion exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Declare your function first

//Write a function that adds two numbers together
//Call the function, passing `13` and `124` as parameters, and assigning the returned value to a variable `sum`
function sum(a, b){
return a + b;
}
// Call the function and assign to a variable `sum`
let total = sum(13, 124);

console.log(sum);
console.log(total);
8 changes: 6 additions & 2 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

const greeting = createLongGreeting("Daniel", 30);
//Write a function that takes a name (a string) and an age (a number) and returns a greeting (a string)
function nameAndAge(name, age){
return `My name is ${name} and I am ${age} years old.`;
}
const longGreeting = nameAndAge("Daniel", 30);

console.log(greeting);
console.log(longGreeting);
27 changes: 22 additions & 5 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
var mentor1 = "Daniel";
var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";

//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.

// let mentor1 = "Daniel";
// let mentor2 = "Irina";
// let mentor3 = "Mimi";
// let mentor4 = "Rob";
// let mentor5 = "Yohannes";
function upperCase(greeting, nameOfPerson){

let text = `${greeting.toUpperCase()} ${nameOfPerson.toUpperCase()}`;
return text;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All the content of the function need to be indented forward.

}

console.log(upperCase("Hi", "Daniel"));
console.log(upperCase("Hi", "Irina"));
console.log(upperCase("Hi", "Mimi"));
console.log(upperCase("Hi", "Rob"));
console.log(upperCase("Hi", "Yohannes"));


3 changes: 2 additions & 1 deletion extra/3-magic-8-ball.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**

const matchers = require(“jest-extended”);
expect.extend(matchers);
Let's peer into the future using a Magic 8 Ball!
https://en.wikipedia.org/wiki/Magic_8-Ball

Expand Down
21 changes: 14 additions & 7 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
// There are syntax errors in this code - can you fix it to pass the tests?

function addNumbers(a b c) {
//addNumbers adds numbers correctly
function addNumbers(a, b, c) {
return a + b + c;
}
console.log(addNumbers(3, 4, 6));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In the test, we don't want to leave any debugging content.
All the console.logs are for debuggying purposes only. You should remove them from test files.
The tests will call the functions at the end of the file and check the results.


//introduceMe function returns the correct string
function introduceMe(name, age)
return "Hello, my name is " + name "and I am " age + "years old";

{
let message = `Hello, my name is ${name} and I am ${age} years old`;
return message;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

} doesn't need an indent here.

console.log(introduceMe("Sonjide", 27));

//getTotal returns a string describing the total
function getTotal(a, b) {
total = a ++ b;

return "The total is total";
let total = a + b;
return "The total is " + total ;
}

console.log(getTotal(23, 5))
/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
34 changes: 28 additions & 6 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
// The syntax for this function is valid but it has an error, find it and fix it.

//trimWord trims leading and trailing whitespace
function trimWord(word) {
return wordtrim();
return word.trim();
}
// console.log(trimWord("CodeYourFuture "));

function getStringLength(word) {
return "word".length();
// //trimWord doesn't remove whitespace in the middle of the string
// function trimSentence(sentence) {
// return sentence.trim();
// }
// console.log(trimSentence(" CodeYourFuture teaches coding "));

//getStringLength returns the length of a word
function getStringLength(word) {
return word.length;
}
// console.log(getStringLength("Turtles"));

// //getStringLength returns the length of a sentence
// function getStringLength(sentence) {
// return sentence.length;
// }
// console.log(getStringLength("A wild sentence appeared!"));

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Indent

}
// console.log(multiply(2, 3, 6));

//multiply multiplies different numbers
// function multiply(a, b, c) {
// return a * b * c;
// }
// console.log(multiply(2, 3, 4));
/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
9 changes: 7 additions & 2 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
// Add comments to explain what this function does. You're meant to use Google!
//return Math.random() * 10 - It returns a random number between 0 and 9 where 0 and 9 are included.
function getRandomNumber() {
return Math.random() * 10;
}

// Add comments to explain what this function does. You're meant to use Google!
// Add comments to explain what this function does. You're meant to use Google!
//return word1.concat(word2) - Joins word1 and word2.
function combine2Words(word1, word2) {

return word1.concat(word2);
}

//Join firstWord, secondWord and thirdWord.
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 this function is expected to return.
return firstWord.concat( " ", secondWord, " ", thirdWord);
}

console.log(concatenate("code", "your", "future"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Again, no console.log should be here.

/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
20 changes: 18 additions & 2 deletions mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
Sales tax is 20% of the price of the product.
*/

function calculateSalesTax() {}
function calculateSalesTax(priceOfProduct) {
let priceProductTax = priceOfProduct + (priceOfProduct * 20) / 100;
return priceProductTax;
}

console.log(calculateSalesTax(15));
console.log(calculateSalesTax(17.50));
console.log(calculateSalesTax(34));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Again, no console.log should be here.

/*
CURRENCY FORMATTING
===================
Expand All @@ -17,7 +23,17 @@ function calculateSalesTax() {}
Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
*/

function addTaxAndFormatCurrency() {}

function addTaxAndFormatCurrency(calculateSalesTax) {
let priceProductTax = calculateSalesTax + (calculateSalesTax * 20) / 100;
let taxFormat = `£${priceProductTax.toFixed(2)}`;
return taxFormat;
}
console.log(addTaxAndFormatCurrency(15));
console.log(addTaxAndFormatCurrency(17.5));
console.log(addTaxAndFormatCurrency(34));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Again, no console.log should be here.




/*
===================================================
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Exercises for JS1 Week 1",
"license": "CC-BY-SA-4.0",
"scripts": {
"test": "jest"
"test": "jest","extra-tests":"jest extra"

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 don't need to change this file.
If you run npm test it runs all the tests for you anyways.

},
"repository": {
"type": "git",
Expand Down