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: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.formatOnSave": true,
"editor.formatOnPaste": true
}
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", "I am very new at this, Lets see if this worked");
// console.log(I am very new at this);
console.log(5);
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 = "Hi there";
console.log(greeting);
console.log(greeting);
console.log(greeting);
2 changes: 2 additions & 0 deletions exercises/D-strings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ In programming there are different _types of_ data. You've used one data type al

Computers recognise strings as a sequence of characters but to humans, strings are simply lines of text.


```js
var message = "This is a string";
```
Expand All @@ -17,6 +18,7 @@ var messageType = typeof message;
console.log(messageType); // logs 'string'
```


## Exercise

- Write a program that logs a message and its type
Expand Down
5 changes: 4 additions & 1 deletion exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Start by creating a variable `message`
var message = "This is a string exercise";
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 greetingStart = "Hello, my name is ";
var myName = "Berenice";

console.log(message);
var greeting = greetingStart + myName;

console.log(greeting);
5 changes: 1 addition & 4 deletions exercises/F-strings-methods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ console.log(nameLength); // Logs 6
You can also get a modified version of a string by calling _string methods_. Let's try one:

```js
var name = "Daniel";
var nameLowerCase = name.toLowerCase();

console.log(nameLowerCase); // "daniel"
"" // "daniel"
```

You can find out more about string properties and methods by searching for "JavaScript string methods".
Expand Down
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`

console.log(message);
const greetingStart = "My name is ";
const myName = "Daniel"
const namePlusLength = " and my name is 6 characters long"

console.log(greetingStart + myName + namePlusLength);
19 changes: 17 additions & 2 deletions exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
const name = " Daniel ";
const greetingStart = "My name is ";
const myName = " Daniel "
const namePlusLength = " and my name is 6 characters long"
const message = myName.trim();

console.log(message);
console.log(myName.trim());







// const name = " Daniel ";
// const message = name.trim();

// console.log(message);
// //was not sure if i should combine the X2 exercises

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not sure either, but great use of .trim(), good method to remember

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`

let numberOfStudents = 15;
let numberOfMentors = 8;

console.log(numberOfStudents + numberOfMentors);
9 changes: 7 additions & 2 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
var numberOfStudents = 15 / 23;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just a tip to keep the original request before you change it. Its not wrong but just helps for troubleshooting. So for e.g. perhaps you could have had:
var numberOfStudents = 15 ;
numberOfStudents = 15/23

Also need to multiply by 100 to get percentage before using Math.round. So perhaps in addition
studentsPercentage = Math.round(numberOfStudents * 100)
console.log( {studentsPercentage}% )

var percentagePerGroup = Math.round(numberOfStudents);
console.log(numberOfStudents);

var numberOfMentors = 8 / 23;
var percentagePerGroup = Math.round(numberOfMentors)
console.log(numberOfMentors);
2 changes: 1 addition & 1 deletion exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Complete the function so that it takes input parameters
function multiply() {
function multiply(num1, num2) {
// Calculate the result of the function and return it

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Inside the function the calculation needs to occur and answer be returned.
return num1 * num2

}

Expand Down
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;
total = a + b;

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

great understanding of the fundamentals in this exercise

/*
Expand Down
7 changes: 3 additions & 4 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// The syntax for this function is valid but it has an error, find it and fix it.

function trimWord(word) {
return wordtrim();
return trimWord();
}

function getStringLength(word) {
return "word".length();
return word.length();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi. This one is similar to the top in exercises, where u got the trim function right.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

here length is a property not a method, that is it should not have () parenthesis after the word.

}

function multiply(a, b, c) {
a * b * c;
return;
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.

This is syntactically correct, just instead of pluses it should have been multiplication

}

/*
Expand Down
7 changes: 7 additions & 0 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
function getRandomNumber() {
return Math.random() * 10;
}
//the function will get numbers between 1 and 10 and round it up or down

// Add comments to explain what this function does. You're meant to use Google!
function combine2Words(word1, word2) {
return word1.concat(word2);
}
// /two words will be combined to form a new word

function concatenate(firstWord, secondWord, thirdWord) {
var one = "firstWord"
var two = "secondWord"
var three = "thirdWord"

console.log(one + two + three);
// 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.
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this definitely will work, but the requirement asks you to use the concat function used just before.

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