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
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.formatOnPaste": true,
"editor.formatOnSave": true
}
Binary file added exercises/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions exercises/B-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ 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
- Open a terminal windowcd exercises/B-hello-world
- Change directory to this folder (``) - assuming you're at the project root
- Run the program using node (`node exercise.js`)

### 2. Experiment
Expand Down
3 changes: 3 additions & 0 deletions 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!')

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);
6 changes: 5 additions & 1 deletion 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";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

try to avoid using var; it can cause issues with scoping https://www.freecodecamp.org/news/var-let-and-const-whats-the-difference/ (you're not expected to understand what this means currently, just here in case you're interested). Try to always use const, then, if the variable needs reassigning, delcare with let instead

var messageType = typeof message;

console.log(messageType);


console.log(message);
6 changes: 5 additions & 1 deletion 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`
var message = "Hello, my name is ";
var name = "Micheal";

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

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`
const name = " Daniel ";
name = "Daniel";
var nameLowerCase = name.toLowerCase();

console.log(nameLowerCase);

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

console.log(nameLowerCase);


console.log(message);
5 changes: 5 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
numberOfStudents = 15;
numberOfMentors = 8;
total = numberOfMentors + numberOfStudents
Comment on lines +2 to +4

@JDysiewicz JDysiewicz Nov 26, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Variables in JavaScript need to be "declared"; this means you prefix the variable name with let or const (e.g. const numberOfStudents = x, let numberOfMentors = y. This is effectively letting JS know that numberOfStudents refers to a variable, instead of being some other key word. This is causing some tests to fail


console.log(total);
13 changes: 11 additions & 2 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
var preciseAge = 30.612437;
var roughAge = Math.round(preciseAge);
numberOfStudents = 15;
numberOfMentors = 8;
total = numberOfMentors + numberOfStudents
var percentageOfStudents = (numberOfStudents/total)*100
let percentageOfMentors = (numberOfMentors/total)*100
var roughStudents = Math.round(percentageOfStudents);
var roughMentors = Math.round(percentageOfMentors);
console.log(roughMentors);
console.log(roughStudents);
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*.5

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

variables are case-sensitive; in this case you want to refer to the number variable; but instead you're referring to something called Number (which, incidentally, is a thing that exists in JS)

}

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

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

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

function name(a,b) {
return a/b

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What would happen if b = 0; you would execute a/0 - give this a try and see what happens; have a think about how you might handle that situation (note - this is more advanced than strictly necessary at this point, but it's always good to think ahead)


}
var result = divide(3, 4);

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

function name(a,b) {
return
}
var greeting = createGreeting("Daniel");

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

function name(a,b) {
return a+b

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

var sum= name(1,2)
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(a, b) {
return "I am " + a + " and I am " + b + " years old"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As a general comment, how might you rewrite this as a template string? Usually, template strings are preferred to string concatenation (especially when there are many variables involved), as it's usually more readable.

}

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

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

function mentorUpperCase(a) {
return a.toUpperCase();
}

function shoutyGreeting(a) {
let nameUpperCase = mentorUpperCase(a);
return "HELLO".concat(" ", nameUpperCase);
}

console.log(shoutyGreeting(mentor1));
console.log(shoutyGreeting(mentor2));
console.log(shoutyGreeting(mentor3));
console.log(shoutyGreeting(mentor4));
console.log(shoutyGreeting(mentor5));
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;
let total = a + b;

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

/*
Expand Down
8 changes: 4 additions & 4 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 getStringLength(word) {
return "word".length();
return word.length;
}

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

}

/*
Expand Down
4 changes: 2 additions & 2 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
function getRandomNumber() {
return Math.random() * 10;
}

// picks a random value to times with ten
// Add comments to explain what this function does. You're meant to use Google!
function combine2Words(word1, word2) {
return word1.concat(word2);
}

// connects two strings together
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.
Expand Down
9 changes: 8 additions & 1 deletion mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
Sales tax is 20% of the price of the product.
*/


function calculateSalesTax() {}

function calculateSalesTax(sales) {
const calcTax = sales * 0.2 + sales;
return calcTax;
}
Comment on lines 9 to +14

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You're declaring the same function name twice here, which is why one of your tests is failing. You can remove the declaration on line 9.

/*
CURRENCY FORMATTING
===================
Expand All @@ -16,8 +21,10 @@ function calculateSalesTax() {}

Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
*/

function addTaxAndFormatCurrency() {}
function addTaxAndFormatCurrency(sales) {
return "£" + calculateSalesTax(sales).toFixed(2);
n

/*
===================================================
Expand Down