Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
Closed
2 changes: 1 addition & 1 deletion exercises/A-setup-ide/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
There are some tools that will help you to write code. One of these, [Prettier](https://prettier.io/), formats your code, making it easier for you and others to read.
There are some tools that will help you to write code. One of these, [Prettier](https://prettier.io/), formats your code, making it easier for you and others to read.

### 1. Install prettier

Expand Down
4 changes: 4 additions & 0 deletions exercises/B-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ Inside of `exercise.js` there's a line of code that will print "Hello world!".

- Try to `console.log()` something different. For example, 'Hello World. I just started learning JavaScript!'.
- Try to console.log() several things at once.

- What happens when you get rid of the quote marks?
When executing "node exercise.js" from the terminal with no quote marks I received the error "SyntaxError: missing ) after argument list, which makes sense as with no quotation marks the debugger/interpreter is expecting only a one word value within the brackets while with the quotation marks it is expecting a string which can have multiple words with spaces".

- What happens when you console.log() just a number without quotes?
The output is a value and is highlighted in a base colour in the terminal, however, if a number is put into quotation marks it becomes a string and is highlighted in a different (string) colour.
8 changes: 8 additions & 0 deletions exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
console.log("Hello world");

console.log("Hello World. I just started learning JavaScript!");

console.log(12);

console.log("12");

console.log(Hello World. No Quotes!);
9 changes: 7 additions & 2 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`
// Program to print a `greeting` variable in the console 3 times
// Tried to reduce code repetition by using a for loop

console.log(greeting);
let greeting = ". Hello world";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why there is dot before hello world text ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the feedback Ibrahim,

By using a for loop to create the three console log messages I was able to then use its count variable "i" to add a preceding number to each message and display,

  1. Hello world
  2. Hello world
  3. Hello world

So, the second character in the above messages is the dot before the hello world text :)


for (let i = 1; i < 4; i++) {
console.log(i + greeting);
}
29 changes: 27 additions & 2 deletions exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
// Start by creating a variable `message`
// Program that selects one of the three basic types of variables then outputs it along with its type.
// Hopefully its ok that I added some randomness to this exercise by highlighting the three main data types,
// If not or it causes jest to fail I will re-write, it was fun though and has a 3:1 chance of printing the expected result :)

console.log(message);
// Declare and initialise variables.
let messageChoice = 0;
let messageType;
let message = "";

// Set `messageChoice` variable to a random number between 0 and 2 rounded to the nearest integer.
messageChoice = Math.round(Math.random() * 2);

// Determine which message to display using the random `messageChoice` value.
if (messageChoice == 0) {
message = "This is a string";
} else if (messageChoice == 1) {
message = 25.5;
} else {
message = true;
}

// Sets `messageType` variable equal to the variable `message` type (string, number or boolean).
messageType = typeof message;

// Outputs the selected `message` and `messageType`
console.log(`
${message}
${messageType}`);
11 changes: 9 additions & 2 deletions exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
// Start by creating a variable `message`
// Program which states my first name to practice concatenation.

console.log(message);
// Set and initialise variables and constants
const MY_NAME = "Andrew";
let greetingStart = "Hello, my name is ";
let greeting = "";

// Update and output `greeting`
greeting = greetingStart + MY_NAME;
console.log(greeting);
18 changes: 17 additions & 1 deletion exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// Start by creating a variable `message`
// Program that outputs a concatenated string stored in variable `message` containing constant `myName`
// and constant `nameLength` after calculating `myNames` character length using string method .length.
// I used constants here as `myName` will never change and consequently its length wont either, however
// the variable `message` concatenation may be updated so I declared it using let

// Declare and initialise variables and constants
const MY_NAME = "Andrew";
const NAME_LENGTH = MY_NAME.length;
let message = "";

// Update Message & output message
message =
"My name is " +
MY_NAME +
" and my name is " +
NAME_LENGTH +
" characters long";

console.log(message);
17 changes: 16 additions & 1 deletion exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
const name = " Daniel ";
// This program performs the same basic function as exercise.js
// however using the string method .trim() to remove the white space
// at both sides of the string " Daniel ".

// Declare and initialise variables and constants
const MY_NAME = " Daniel ".trim();
const NAME_LENGTH = MY_NAME.length;
let message = "";

// Update Message & output message
message =
"My name is " +
MY_NAME +
" and my name is " +
NAME_LENGTH +
" characters long";

console.log(message);
20 changes: 19 additions & 1 deletion exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
// Program that outputs the value of `numberOfStudents`, `numberOfMentors`
// and `totalStudentsAndMentors` after using template string literal syntax to concatenate
// the string stored in `message`.

// Declare and initialise variables
let numberOfStudents = 15;
let numberOfMentors = 8;
let totalStudentsAndMentors = 0;
let message = "";

// Calculate total number of students
totalStudentsAndMentors = numberOfStudents + numberOfMentors;

// Concatenate string
message = `Number of students: ${numberOfStudents}
Number of mentors: ${numberOfMentors}
Total number of students and mentors: ${totalStudentsAndMentors}`;

console.log(message);
31 changes: 29 additions & 2 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
// Program to calculate the percentage of students and mentors in a group.

// Declare and initialise variables
let numberOfStudents = 15;
let numberOfMentors = 8;
let percentValue = 0;
let percentageStudents = 0;
let PercentageMentors = 0;
let result = "";

// Set `percentValue` value equal to the actual percentage value for the group size as
// this reduces the required nesting and hopefully makes the code easier read.
percentValue = 100 / (numberOfStudents + numberOfMentors);

// Performed main calculations using Math.round for both students and mentors,
// storing the results in their respective variables. Alternatively I could have calculated
// only one of the percentages then subtracted it from 100 (which I think would have been more efficient)
// but felt the spirit of the exercise was to use Math.floor so did it this way.
percentageStudents = Math.round(percentValue * numberOfStudents);
PercentageMentors = Math.round(percentValue * numberOfMentors);

// String literal syntax is used to concatenated a `result` string
result = `
Percentage students: ${percentageStudents}%
Percentage mentors: ${PercentageMentors}%
`;

// Output the result to the console
console.log(result);
12 changes: 9 additions & 3 deletions exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
function halve(number) {
// complete the function here
// Function to half the input parameter `number`
return result = number / 2;
}

var result = halve(12);
// Testing with specified input which also produces an integer value output
console.log(halve(12));

console.log(result);
// Testing with an input that produces a float value output
console.log(halve(1));

// Testing 0 just to see what happens :)
console.log(halve(0));
12 changes: 9 additions & 3 deletions exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
function triple(number) {
// complete function here
// Function to triple the input parameter `number`
return (result = number * 3);
}

var result = triple(12);
// Testing with specified integer input that should produces an integer value output
console.log(triple(12));

console.log(result);
// Testing with a float input that should produce a float output
console.log(triple(0.3));

// Testing with 0 for fun again :)
console.log(triple(0));
16 changes: 10 additions & 6 deletions exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// Complete the function so that it takes input parameters
function multiply() {
// Calculate the result of the function and return it
function multiply(numOne, numTwo) {
// Function to multiply two parameters together
return (result = numOne * numTwo);
}

// Assign the result of calling the function the variable `result`
var result = multiply(3, 4);
// Testing by calling the function with suggested parameters
console.log(multiply(3, 4));

console.log(result);
// Testing by calling the function with two float parameters
console.log(multiply(3.5, 4.7));

// Testing with calling the function with 0 as parameters
console.log(multiply(0, 0));
16 changes: 13 additions & 3 deletions exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// Declare your function first
function divide(numOne, numTwo) {
// Function to divide two parameters together
return (result = numOne / numTwo);
}

var result = divide(3, 4);
// Testing by calling the function with suggested parameters
console.log(divide(3, 4));

console.log(result);
// Testing by calling the function with two float parameters
console.log(divide(3.5, 4.7));

// Testing with calling the function with 0 as parameters, interesting
// unlike the previous multiply function which produced a 0, this
// produces a NaN...
console.log(divide(0, 0));
9 changes: 5 additions & 4 deletions exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Write your function here
function greeting(myName) {
// Function takes myName parameter (string) and adds it to a greeting
return `Hello, my name is ${myName}`;
}

var greeting = createGreeting("Daniel");

console.log(greeting);
console.log(greeting("Daniel"));
15 changes: 12 additions & 3 deletions exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
// Declare your function first
function add(numOne, numTwo) {
// Function to add two parameters together
let sum = numOne + numTwo;
return sum;
}

// Call the function and assign to a variable `sum`
// Testing by calling the function with suggested parameters
console.log(add(13, 124));

console.log(sum);
// Testing by calling the function with two float parameters
console.log(add(3.5, 4.7));

// Testing with calling the function with 0 as parameters
console.log(add(0, 0));
10 changes: 6 additions & 4 deletions exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Declare your function here
function createLongGreeting(myName, myAge) {
// Function takes myName parameter (string) and adds it to a greeting
return `Hello, my name is ${myName} and I'm ${myAge} years old`;
}

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

console.log(greeting);
// Testing by calling the function with suggested parameters.
console.log(createLongGreeting("Daniel", 30));
21 changes: 16 additions & 5 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
var mentor1 = "Daniel";
var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";
// I hope the way I have solved this exercise is ok although the readme seemed to have
// some wiggle room (hope jest does!) but happy to redo if needed as I enjoyed thinking
// of an alternative solution. As its the last exercise I wanted to try and be a bit creative
// so to solve this I have put the pre-defined mentor names into an array then iterated
// through it using a for loop which contains two nested ES6 arrow functions with omitted
// return and curly brackets as they are on one line. Had great fun figuring out how to
// solve it like this:)

let mentors = ["Daniel", "Irina", "Mimi", "Rob", "Yohannes"];

for (let i = 0; i < mentors.length; i++) {
let mentor = mentors[i];
const getNameInUpperCase = (mentor) => mentor.toUpperCase();
const shoutyGreeting = (mentor) => `HELLO ${getNameInUpperCase(mentor)}`;
console.log(shoutyGreeting(mentor));
}