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

Westmidlands-class 4-farzad-nazif- JavaScript-Core-1-Coursework-Week1 - #332

Closed
farzad-nazif wants to merge 3 commits into
CodeYourFuture:masterfrom
farzad-nazif:master
Closed

Westmidlands-class 4-farzad-nazif- JavaScript-Core-1-Coursework-Week1#332
farzad-nazif wants to merge 3 commits into
CodeYourFuture:masterfrom
farzad-nazif:master

Conversation

@farzad-nazif

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: Farzad Nazif
  • Your City: Westmidlands - Birmingham
  • Your Slack Name: Farzad-nazif

Homework Details

  • Module: JavaScript-Core-1
  • Week: 1

Notes

  • What did you find easy?
    understanding the var and functions

  • What did you find hard?
    the last challenge of extra folder

  • What do you still not understand?

  • Any other notes?

@JanefrancessC JanefrancessC 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.

Fantastic job!

function convertToBRL(price) {
let priceToBeConverted = 0.99*price;
let convertedPrice = priceToBeConverted * 5.7;
return parseFloat(convertedPrice.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.

Nice job with the parseFloat(). I just got to know about it from reviewing your codes... Great job Farzad!

function getRandomNumber() {
return Math.random() * 10;
}
// Comment : math.random gives us a random number between 0 and 1. then we times it by 10, we will have a random number between 0 and 10.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

From my findings on Google, I could be wrong though, the getRandomNumber function will generate only floating numbers between 1 - 10

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.

math.random() gives you a number between 0 and 1 , if you times it by 10 , then gives you 0 to 10

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

"The Math.random() function returns a floating-point, pseudo-random number in the range 0 to less than 1 (inclusive of 0, but not 1) with approximately uniform distribution over that range — which you can then scale to your desired range. "

As you can see from the description taken from MDN Docs above, math.random() will randomly generate a number between 0 and 1. After that, it will multiply a number of your choice.

Comment thread mandatory/4-tax.js
}

/*
===================================================

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Had a great time going through your codes. it gave me alternate perspectives to solve a problem!

Thumbs up Farzad!

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 a lot Chioma

@alicagatay alicagatay 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.

Nice job Farzad, I really liked the way you solved some of these problems. Keep up the good work.

function addNumbers(a b c) {
function addNumbers(a, b, c) {
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.

Correct, as you can see, while setting up parameters in a function, you need to separate them with commas.

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";
}

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, when writing JavaScript functions, you need to use curly brackets to define the inside of the function, otherwise JavaScript won't understand that part and throw an error. In addition, as you did above, you need to put the + icon between strings and variables, so that you can concatenate them.


function getTotal(a, b) {
total = a ++ b;
total = 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.

Don't forget the let keyword while defining a variable!


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.

Another nice way of concatenating a String with a variable. In addition, you can also use String interpolation to do this.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That's right. There is no function called wordtrim() in JavaScript. We use trim() instead.

function getRandomNumber() {
return Math.random() * 10;
}
// Comment : math.random gives us a random number between 0 and 1. then we times it by 10, we will have a random number between 0 and 10.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

"The Math.random() function returns a floating-point, pseudo-random number in the range 0 to less than 1 (inclusive of 0, but not 1) with approximately uniform distribution over that range — which you can then scale to your desired range. "

As you can see from the description taken from MDN Docs above, math.random() will randomly generate a number between 0 and 1. After that, it will multiply a number of your choice.

function combine2Words(word1, word2) {
return word1.concat(word2);
}
// Comment : This functions takes 2 parametrs and append word2 to word 1 (combine) and return a new 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.

That's correct, this function will concatenate 2 given Strings.

let wordCombination = firstWord.concat(secondWord);
let final = wordCombination.concat(thirdWord);
return final;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That's correct.

Comment thread mandatory/4-tax.js
function calculateSalesTax(productPrice) {
let total = productPrice + productPrice * 0.2;
return 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.

That's correct, I also like the way you calculated the total value in just 1 line, nice job.

Comment thread mandatory/4-tax.js
function addTaxAndFormatCurrency(productPrice) {
let total = calculateSalesTax(productPrice);
return "£" + total.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.

This is also correct. In addition to this way, you can also use String interpolation to concatenate a String to a variable.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants