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
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/exercises/B-hello-world/exercise.js"
}
]
}
2 changes: 1 addition & 1 deletion exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log("Hello world");
console.log("Hello World. I just started learning JavaScript!");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Excellent.

2 changes: 1 addition & 1 deletion exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Start by creating a variable `greeting`

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

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 have declared and used the variable correctly however we also want you to print it three times. You could do this using a for loop as we have looked at for repeating code in class.

21 changes: 20 additions & 1 deletion exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
// Start by creating a variable `message`

console.log(message);
let messageChoice = 0;
let messageType;
let message = "";

messageChoice = Math.round(Math.random() * 2);


if (messageChoice == 0) {
message = "This is a string";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If you have a variable like messageChoice where you know what the type should be (this is true most of the time) it's good practice to use a strict equality check which means the === operator as opposed to ==. What this means is that the computer will check that not only do your variables / values represent the same 'soft value', but they also have the same type.

For example 0 == "0" is true, even though the left-hand value is a number and the right-hand value is a string. However 0 === "0" is false, since the values are not the same type.

} else if (messageChoice == 1) {
message = 25.5;
} else {
message = true;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It's really good to try out different things like you've done here as it definitely helps with understanding them better!! However, if you do this you can also put it in a separate file just in case it interferes with the assigned task.

messageType = typeof message;

console.log(`
${message}
${messageType}`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Excellent. Good to try out string interpolation as a way of outputting variables.

8 changes: 7 additions & 1 deletion exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Start by creating a variable `message`

console.log(message);
const MY_NAME = "Omer";
let greetingStart = "Hello, my name is ";
let greeting = "";

greeting = greetingStart + MY_NAME;

console.log(greeting);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Excellent.

10 changes: 10 additions & 0 deletions exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// Start by creating a variable `message`
const MY_NAME = "Omer";
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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Excellent.

13 changes: 13 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
let numberOfStudents = 15;
let numberOfMentors = 8;
let totalStudentsAndMentors = 0;
let message = "";

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

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 can simplify this by initialising the variable and setting its value at the same time.

I.e.:

let totalStudentsAndMentors = numberOfStudents + numberOfMentors;

(so you no longer need line 4)


// Concatenate string
message = `Number of students: ${numberOfStudents}
Number of mentors: ${numberOfMentors}
Total number of students and mentors: ${totalStudentsAndMentors}`;
console.log(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.

Excellent. Again, you could do let message = on line 11 and define the variable at the same time as you set its value. This can sometimes be safer, as it means you'll get an error message saying the variable is undefined if you try to use it before it has been set correctly. This is helpful as then you'll know there's something wrong.

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 (result = number / 2);
}

var result = halve(12);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Excellent.

Expand Down