Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
Open
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ The exercises are split into three folders: `exercises`, `mandatory` and `extra`

The `extra` folder contains exercises that you can complete to challenge yourself, but are not required for the following lesson.

## Running the code/tests
Running the code/tests

The files for the mandatory/extra exercises are intended to be run as jest tests.

- Once you have cloned the repository, run `npm install` once in the terminal to install jest (and any necessary dependencies).
- To run the tests for all mandatory/extra exercises, run `npm test`
- To run only the tests for the mandatory exercises, run `npm test -- --selectProjects mandatory`
- To run only the tests for the extra exercises, run `npm test -- --selectProjects extra`
- To run a single exercise/test (for example `mandatory/1-writer.js`), run `npm test -- --testPathPattern mandatory/1-writer.js` (Remember, you can use tab-completion to get files relative to the current directory, so m`Tab ↹`/1-`Tab ↹` will autocomplete get you the test file starting with 1-)
- To run a single exercise/test (for example `mandatory/1-writer.js`), ` (Remember, you `npm test -- --testPathPattern mandatorycan use tab-completion to get files relative to the current directory, so m`Tab ↹`/1-`Tab ↹` will autocomplete get you the test file starting with 1-)

For more information about tests, look here:

Expand Down
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 exercises/B-hello-w`orld`) - assuming you're at the project root
- Run the program using node (`node exercise.js`)

### 2. Experiment
Expand Down
1 change: 1 addition & 0 deletions 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 just started learning JavaScript!.");
2 changes: 1 addition & 1 deletion exercises/C-variables/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The program above will print "Hello world" to the console. Notice how it uses th
- Add a variable `greeting` to exercise.js (make sure it comes _before_ the console.log)
- Print your `greeting` to the console 3 times

> Remember: to run this exercise you must change directory to the `C-variables`. If you already have a terminal window open for the previous exercise you can do this by running the command `cd ../C-variables`.
> Remember: to run this exercise you must change directory to the `C-variables`. If you already have a terminal window open for the previous exercise you can do this by running the command ` .cd./C-variables`.

## Expected result

Expand Down
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);
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`

console.log(message);
var message = "This is the string "
var messageType = typeof message;
console.log(messageType);
6 changes: 4 additions & 2 deletions exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Start by creating a variable `message`

console.log(message);
var greetingStart = "Hello, my name is ";
var name = "Daniel";
var greeting = greetingStart + name;
console.log(greeting);
5 changes: 3 additions & 2 deletions exercises/F-strings-methods/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 name = "Justinas";
var nameLength = name.length;
console.log(nameLength);
6 changes: 4 additions & 2 deletions exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const name = " Daniel ";
const greetingStart = "Hello, my name is ";
const name = " Justinas ";
const greeting = greetingStart + name;

console.log(message);
console.log(greeting);
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`
const numberOfStudents = 15;
const numberOfMentors = 8;
const totalNumbers = numberOfStudents + numberOfMentors;
console.log(totalNumbers);
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;
}

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;
}

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(number) {
return number * 4;
}

// 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,5 +1,7 @@
// Declare your function first

function divide(number){
return number / 4;
}
var result = divide(3, 4);

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

function add (number){
return number;
}
// Call the function and assign to a variable `sum`
var sum = add (13 + 124);

console.log(sum);


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,4 +1,7 @@
// Declare your function here
function createLongGreeting(name, age){
return greeting = 'Hello, my name is + name + and I am +age + years old'
}

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

Expand Down
6 changes: 3 additions & 3 deletions exercises/L-functions-nested/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ function getAgeInDays(age) {
return age * 365;
}

function createCreeting(name, age) {
createCreeting(name, age) {
var ageInDays = getAgeInDays(age);
var message =
"My Name is " + name + " and I was born over " + ageInDays + " days ago!";
"My Name is " + name + " and I was born over " + ageInDaysfunctio + " days ago!";
return message;
}
```
Expand All @@ -29,6 +29,6 @@ function createCreeting(name, age) {
HELLO DANIEL
HELLO IRINA
HELLO MIMI
HELLO ROB
HELLO ROBunction createCreeting(name, age
HELLO YOHANNES
```
24 changes: 19 additions & 5 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
var mentor1 = "Daniel";
var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";


const mentor1 = "Daniel";
const mentor2 = "Irina";
const mentor3 = "Mimi";
const mentor4 = "Rob";
const mentor5 = "Yohannes";

function getMentorsUppercase(mentor){
return mentor.toUpperCase();
}
function concatShoutyGreeting(mentor){
return "HELLO " + getMentorsUppercase(mentor);
}
console.log(concatShoutyGreeting(mentor1));
console.log(concatShoutyGreeting(mentor2));
console.log(concatShoutyGreeting(mentor3));
console.log(concatShoutyGreeting(mentor4));
console.log(concatShoutyGreeting(mentor5));
12 changes: 6 additions & 6 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// 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;

return "The total is total";
return "The total is " + (a + b) ;

}

/*
Expand Down
11 changes: 7 additions & 4 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// 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
9 changes: 6 additions & 3 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
// 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! The Math.random() function returns a floating-point, pseudo-random number in the range 0 to less than 1 (inclusive of 0, but not 1) with approximately uniform distribution over that range — which you can then scale to your desired range. The implementation selects the initial seed to the random number generation algorithm; it cannot be chosen or reset by the user.
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!The concat() method joins two or more strings. The concat() method does not change the existing strings. The concat() method returns a new string.

function combine2Words(word1, word2) {
return word1.concat(word2);
}

function concatenate(firstWord, secondWord, thirdWord) {
return firstWord.concat(" " + secondWord.concat(` ${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.
}

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

function calculateSalesTax() {}
function calculateSalesTax(amount) {
return amount *1.2;

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

function addTaxAndFormatCurrency() {}

function addTaxAndFormatCurrency(number) {
return '\u00A3' + calculateSalesTax(number).toFixed(2);
}

/*
===================================================
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@
"url": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1/issues"
},
"jest": {
"setupFilesAfterEnv": ["jest-extended"],
"setupFilesAfterEnv": [
"jest-extended"
],
"projects": [
{
"displayName": "mandatory",
"testMatch": ["<rootDir>/mandatory/*.js"]
"testMatch": [
"<rootDir>/mandatory/*.js"
]
},
{
"displayName": "extra",
"testMatch": ["<rootDir>/extra/*.js"]
"testMatch": [
"<rootDir>/extra/*.js"
]
}
]
},
Expand Down