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 exercises/B-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ 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?
- What happens when you console.log() just a number without quotes?
- What happens when you get rid of the quote marks? Face with SyntaxError(missing ) after argument list)
- What happens when you console.log() just a number without quotes? Face with SyntaxError(missing ) after argument list)

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 Leila

You're very close with the answer, the last answer isn't quite correct but I definitely see your logic for this one, you can try to run console.log(10); and see the result 👍

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!" );
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`

let greeting="Hi Leila"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good work not using var here! The greeting can actually be a const which is short for "constant" meaning the value never changes.

There will be other areas in this PR where const should be used instead of let or var but since the exercises didn't help with this - I won't mention it further on and you don't need to action it 👍

console.log(greeting);
console.log(greeting);
console.log(greeting);
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`

let message="this is a string"
let messageType=typeof message;
console.log(message);
console.log(messageType);
// console.log(message + " "+ typeof 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.

This works great.

JavaScript does allow you to forget semicolons but we should always add them (line 2), no doubt this was an innocent mistake whilst learning :) I'd always suggest adding spaces between the variable and its assignment just for cleanliness / readability as well, like such (This feedback applies for the full PR):

const message = "this is a string";
const messageType = typeof message;

Finally one other suggestion would be to delete commented out code, it's a very easy thing to leave commented out code in your commits, I do it sometimes in my full time job as well. Here's a link to our style guide on commented out code to explain a little more: https://syllabus.codeyourfuture.io/guides/code-style-guide#dont-leave-lots-of-commented-out-code

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);
let greetingSentence ="Hi my name is";
let name="Leila";
let greeting =greetingSentence +" " + 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);
let name="Leila";
let message=name.length;
console.log("My name is"+" "+name + " "+ "and my name is"+" " + message+" "+ "character long.");

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 passes and does exactly what we need it to do, great work Leila.

We could tidy it up a little, if you notice you are using concatenation to add a space +" "+ after a string. We could just add the space to the string before it instead, for example:

console.log("My name is " + name + " and my name is " + message + " characters long.");

By adding the spaces in the original strings, we have less + symbols and the line becomes a little easier to read.

4 changes: 2 additions & 2 deletions exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const name = " Daniel ";

console.log(message);
const message=name.length;
console.log("My name is" + " " + name.trim() + " " + "and my name is" + " " + message + " " +"character long.");

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 effort, I would apply my previous feedback here regarding the spaces, just so it's a little easier to read. I won't comment any other instances of this suggestion in the PR :)

console.log("My name is " + name.trim() + " and my name is " + message + " character long.");

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=10;
const numberOfMentors=7;
const sum=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.

Perfect 🥇 As I've been advising other students, one thing which is completely optional but will greatly improve the readability of your code is to add parenthesis to comparisons and calculations. When it's just a simple sum like a + b it may not be too clear why it helps, but when there are many calculations or comparisons happening it becomes more clear why it is beneficial.

Your sum variable would become:

const sum = (numberOfStudents + numberOfMentors);

console.log("Total number of students and mentors:" + sum);
6 changes: 6 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
var total = numberOfMentors + numberOfStudents;
let studentPerc = Math.round((numberOfMentors / total) * 100);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well done and very good use of brackets / parenthesis to make the calculation more readable 💯

My only suggestion would be the variable names, whilst studentPerc and mentorPerc are somewhat descriptive, if you imagine 100-200 lines of code, this may be hard to understand. Changing these variables to something like const studentPercentage or even const percentageOfStudents will be much more descriptive and may help the reader easier understand what is happening. (Especially if you had a lot of code).

let mentorPerc = Math.round((numberOfStudents / total) * 100);

console.log("Percent of student :" + " " + studentPerc + "%");
console.log("Percent of mentor :" + " " + mentorPerc + "%");
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 number/2;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Brilliant, this works great.

Just another reminder that it's usually a good idea to use parenthesis when doing any sort of calculation (but it is optional).

function halve(number) {
  return (number / 2);
}

}

var result = halve(12);
Expand Down
1 change: 1 addition & 0 deletions exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function triple(number) {
// complete function here
return number*3;
}

var result = triple(12);
Expand Down
3 changes: 2 additions & 1 deletion exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Complete the function so that it takes input parameters
function multiply() {
function multiply(a,b) {
// Calculate the result of the function and return it
return a*b;
}

// 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(a, b) {
return a / b;
}
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 createGreeting(name){
return "Hello, My name is " + name;
}
var greeting = createGreeting("Daniel");

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

function add(a,b){
return a+b;
}
// Call the function and assign to a variable `sum`

sum=add(13,124);
console.log(sum);
4 changes: 3 additions & 1 deletion 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(name,age){
return "Hello, my name is " + name + " and I'm " + age + " years old";
}
const greeting = createLongGreeting("Daniel", 30);

console.log(greeting);
21 changes: 21 additions & 0 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@

var greet="HELLO";
var mentor1 = "Daniel";
var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";


function upperCase(name){

return name.toUpperCase();
}
function showName(greet,name){
return greet +" "+ upperCase(name);
}
let result1=showName(greet,mentor1);
let result2 = showName(greet, mentor2);
let result3 = showName(greet, mentor3);
let result4 = showName(greet, mentor4);
let result5 = showName(greet, mentor5);
console.log(result1);
console.log(result2);
console.log(result3);
console.log(result4);
console.log(result5);
11 changes: 9 additions & 2 deletions extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

function convertToUSD() {}
function convertToUSD(price) {
price *=1.4;

@Gevie Gevie Sep 16, 2022

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Very good use of multiplication assignment, I haven't seen any other student do this and I don't think we covered it in class, I'm impressed! Well done. 🥇

return price;
}

/*
CURRENCY CONVERSION
Expand All @@ -15,7 +18,11 @@ function convertToUSD() {}
They have also decided that they should add a 1% fee to all foreign transactions, which means you only convert 99% of the £ to BRL.
*/

function convertToBRL() {}
function convertToBRL(price) {
price*=5.7;
total=(price-(price*1/100)).toFixed(2);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Again good use of multiplication assignment and good use of parenthesis on your total variable.

We could probably use a const before total and we also have a stray + on the return line.

return +total;
}

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
21 changes: 12 additions & 9 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,29 @@
the final result to the variable goodCode
*/

function add() {

function add(num1,num2) {
return num1+num2;
}

function multiply() {

function multiply(num1,num2) {
return num1*num2;
}

function format() {

function format(number) {
return `£${number.toString()}`

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 usage of backticks here Leila. This is the alternative to "£" + number.toString();

I would say backticks like you used here are much better 👍

}

const startingValue = 2;

// Why can this code be seen as bad practice? Comment your answer.
let badCode =
let badCode = `£${(startingValue+10)*2}`


/* BETTER PRACTICE */

let goodCode =
/* BETTER PRACTICE */
const sum=startingValue+10;
const result=sum*2;
let goodCode =`£${result}`;

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
63 changes: 56 additions & 7 deletions extra/3-magic-8-ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,40 @@

// This should log "The ball has shaken!"
// and return the answer.
let fixAnswer = [
"It is certain.", //0
"It is decidedly so.", //1
"Without a doubt.", //2
"Yes - definitely.", //3
"You may rely on it.", //4-very positive
"As I see it, yes.", //5
"Most likely.", //6
"Outlook good.", //7
"Yes.", //8
"Signs point to yes.", //9-positive
"Reply hazy, try again.", //10
"Ask again later.", //11
"Better not tell you now.", //12
"Cannot predict now.", //13
"Concentrate and ask again.", //14-negetive
" Don't count on it.", //15
"My reply is no.", //16
"My sources say no.", //17
"Outlook not so good.", //18
" Very doubtful.", //19-very negetive
];


function shakeBall() {
//Write your code in here
console.log("The ball has shaken!");
randomNumber = Math.floor(Math.random() * fixAnswer.length);
result =fixAnswer[randomNumber];
return result;

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 correct and you've done well Leila, good use of the math library as well 👍

I would just be careful of your indentation as well as use const or let on your new variables, the return line is indented more than the other lines.

Another way you could return your value is just passing fixAnswer[randomNumber] instead of using the variable since it's quite a small line.

function shakeBall() {
  console.log("The ball has shaken!");
  const randomNumber = Math.floor(Math.random() * fixAnswer.length);
  
  return fixAnswer[randomNumber];
}

}



/*
This function should say whether the answer it is given is
- very positive
Expand All @@ -58,10 +88,25 @@ function shakeBall() {

This function should expect to be called with any value which was returned by the shakeBall function.
*/
function checkAnswer(answer) {
//Write your code in here
}

function checkAnswer(answer) {
//Write your code in here
let ballPredict = fixAnswer.indexOf(answer);
if (ballPredict <= 4) {
answer = "very positive";
} else if (ballPredict <= 9) {
answer = "positive";
} else if (ballPredict <= 14) {
answer = "negative";
} else if (ballPredict <= 19) {
answer = "very negative";
} else answer = "Something broken";

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 Leila, you've pretty much hit the nail on the head here 👍

I would just be careful at the end with your } else answer = "Something broken"; as this syntax isn't quite correct. I also notice you define answer then return it at the end, another way of doing this is just to return in each conditional block. For example:

function checkAnswer(answer) {
  const ballPredict = fixAnswer.indexOf(answer);
  
  if (ballPredict <= 4) {
    return "very positive";
  } else if (ballPredict <= 9) {
    return "positive";
  } else if (ballPredict <= 14) {
    return "negative";
  } else if (ballPredict <= 19) {
    return "very negative";
  }
  
  return "Something broken";
}


return answer;
}



/*
==================================
======= TESTS - DO NOT MODIFY =====
Expand All @@ -82,12 +127,16 @@ test("whole magic 8 ball sequence", () => {
expect(consoleLogSpy).toHaveBeenCalledTimes(1);
expect(consoleLogSpy).toHaveBeenLastCalledWith("The ball has shaken!");

expect(checkAnswer(answer)).toBeOneOf([
"very positive",
// expect(checkAnswer(answer)).toBeOneOf([
// "very positive",
// "positive",
// "negative",
// "very negative",
// ]);
expect(["very positive",
"positive",
"negative",
"very negative",
]);
"very negative"]).toContain(checkAnswer(answer))
});

test("magic 8 ball returns different values each time", () => {
Expand Down
12 changes: 7 additions & 5 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// 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.

You have solved the exercises and mandatory problems in a very neat, simple and understandable code and it's great. Well done.

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.

Many thanks :)


/*
Expand Down
14 changes: 10 additions & 4 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
// 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();
}
word = " CodeYourFuture ";

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 successfully completed the exercise by fixing the errors 💯

We are however defining a word variable 4 times in this file, reassigning its value and never actually using the variable anywhere. We can probably delete these lines :)

word = " CodeYourFuture teaches coding ";

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

return word.length;
}
word = getStringLength("A wild sentence appeared!");
word = getStringLength("Turtle"); ;

function multiply(a, b, c) {
a * b * c;
return;
const result= a * b * c;
return result;
}

/*
Expand Down
11 changes: 9 additions & 2 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
// Add comments to explain what this function does. You're meant to use Google!

/* This function creat an integer random number(by multiplying decimal random number by ten)*/
function getRandomNumber() {
return Math.random() * 10;
}

// Add comments to explain what this function does. You're meant to use Google!

/*This function concat two words which will be pass to the function as an argument
for example if word1="ali" and word="reza" the result of this function will be "alireza"*/
function combine2Words(word1, word2) {
return word1.concat(word2);
}

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.
return firstWord + " " + secondWord + " " + thirdWord;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hello Leila, you have done an amazing job and your codes are simple and easy to understand and review. However, I think for the return you could have used .concat to concatenate all the words together like on the above combine2Words function. If there is a reason for not using that do you mind explaining? Thank you

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.

Thank you for your feedback. Yes you are completely right. I just wanted to try every piece of code that we have learnt during course :)

}
firstWord="code";

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've completed this mandatory exercise spot on Leila :)

The only feedback would be that we don't need the firstWord, secondWord and thirdWord variables on line 19 to 21 since they're never used 👍

secondWord="your";
thirdWord="future";

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