Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.

JavaScript week 1 - #255

Closed
mairacagri wants to merge 4 commits into
CodeYourFuture:masterfrom
mairacagri:master
Closed

JavaScript week 1#255
mairacagri wants to merge 4 commits into
CodeYourFuture:masterfrom
mairacagri:master

Conversation

@mairacagri

Copy link
Copy Markdown

Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in HOW_TO_MARK.md in the root of this repository

Your Details

  • Your Name: Maira
  • Your City: London
  • Your Slack Name: Mairacagri

Homework Details

  • Module:JavaScript Core 1
  • Week:1

Notes

  • What did you find easy?multiply divide exercises

  • What did you find hard? nested functions and how to use terminal

  • What do you still not understand? need more practice

  • Any other notes?

@SamanZahedi SamanZahedi left a comment

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 Maira, I have reviewed your work, very well done, great work.

// const greeting = createLongGreeting("Daniel", 30);
function createLongGreeting(name, age){

return `Hello, my name is ${name} and I'm ${age} years old`;

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 use of concat and interpolation overall, the best option

}

function concatenate(firstWord, secondWord, thirdWord) {
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.

There is another way of doing this if you follow the link above

Comment thread mandatory/4-tax.js
function calculateSalesTax() {}

function calculateSalesTax(price) {
let totalPrice = price * 0.2 + price;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

another way is return price * 1.2

@mahsa2 mahsa2 left a comment

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 Maira on completing this assignment, and the time you've spent on it to learn 💪 💯

function multiply() {
function multiply(a , b) {
// Calculate the result of the function and return it
return a *b;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correct spacing:

return a * b;

@@ -1,4 +1,7 @@
// Declare your function first
function divide (a,b){
return a /b;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correct spacing:

return a / b;

@@ -1,7 +1,16 @@
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.

Correct spacing:

return number / 2;

const name = " Daniel ";

console.log(message);
let message = "My name is " + firstName + " and my name is 5 characters 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.

  1. Variable firstName doesn't exist here. You need to use name instead.
  2. Use a string method to calculate the length of your name rather than writing it directly here as 5.
  3. You need to use .trim() on the name to clear extra spacing around it.
  4. It's almost always better to use this format for string concatinations:
    Like this:
name = name.trim()
let message =`My name is ${name} and my name is ${name.length} characters long`

// Start by creating a variables `numberOfStudents` and `numberOfMentors`
let numberOfStudents = 50;
let numberOfMentors = 20;
let result = 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.

Use const when your variable value won't change at all.
Use let when the content of your variable will change later in the code.

Therefore, here you can change all the let to const.

let newPercentageOfStudents= Math.round(percentageOfStudents);
console.log(newPercentageOfStudents);
let percentageOfMentors = numberOfMentors * 100/ total;
let newPercentageOfMentors = Math.round(percentageOfMentors);

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, you can use const in this file instead of all the lets.

function createGreeting (){
let name = "Daniel"
let message = "hello my name is " + name;
return 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.

Indent

var greeting = createGreeting("Daniel");
function createGreeting (){
let name = "Daniel"
let message = "hello my name is " + name;

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, this format is better to use: Hello ... ${name}

Comment thread mandatory/4-tax.js
let totalPrice2 = calculateSalesTax(17.50);
console.log(totalPrice2);
let totalPrice3 = calculateSalesTax(34);
console.log(totalPrice3);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We don't want to keep any debugging code in our tests. We should remove all the console.logs from our test files.
The tests furthur in the file will correctly evaluate the tests.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants