-
-
Notifications
You must be signed in to change notification settings - Fork 42
Java script core 1 homework/week1/osagie #32
base: master
Are you sure you want to change the base?
Java script core 1 homework/week1/osagie #32
Conversation
… parametersanswer no2
Finished the Mandatory, done Extra but have an error on the Add function2 for the piping.js. Not started the Magic-8-balls.js yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done on completing this Osagie, and for attempting the extra work. You've demonstrated good understanding. I would encourage you to revisit the K exercises, where function parameters are missing.
function multiply() { | ||
// Calculate the result of the function and return it | ||
return 3 * 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whilst this does work for the result below, it's not going to work for other numbers. The Exercise asked for this function to work with input parameters to multiple together.
|
||
var result = divide(3, 4); | ||
function divide() { | ||
return 3 / 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, this is not using function parameters. Can you figure out how this function would look using them?
function createGreeting() { | ||
let name = "Daniel"; | ||
let greeting = "Hello, my name is "; | ||
let fullGreeting = greeting + name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you try using greeting
and name
as function parameters?
var mentor5 = "Yohannes"; | ||
//Exercise 1// | ||
function percentProgram(firstNumber, secondNumber) { | ||
let overallTotal = firstNumber + secondNumber; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you have demonstrated using function parameters nicely so I'm sure you can correct the other exercises above :)
function percentProgram(firstNumber, secondNumber) { | ||
let overallTotal = firstNumber + secondNumber; | ||
|
||
let percentage = Math.floor((firstNumber / overallTotal) * 100); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running this exercise returns 65% for students and 34% for mentors. The total is 99% not 100%, can you think why?
function getNumber() { | ||
return Math.random() * 10; | ||
function letterSet() { | ||
return Math.random() * 10; //Math.random() syntax is a floating-point, pseudo-random number between 0 (inclusive) and 1 (exclusive). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you've said here is correct but what else is happening here (look at the * 10
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @pads. Each time the code is ran, it will return random values 0 to 9. Result: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
|
||
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 to expect in return | ||
|
||
return `${firstWord} ${secondWord} ${thirdWord}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice looking solution here!
function formatCurrency(productPrice) { | ||
let salesTax = 0.2; | ||
let taxValue = productPrice * salesTax; | ||
let salesPrice = productPrice + taxValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you thought about how you could use your calculateSalesTax
function inside this function to achieve the same result? This is a good opportunity to practice call functions inside of functions!
|
||
// Why can this code be seen as bad practice? Comment your answer. | ||
let badCode = | ||
let badCode = format(multiply(add(startingValue, 10), 2)); //badCode has all codes mumbled up in one line// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's hard to read isn't it!
let goodCode = | ||
let sum = add(startingValue, 10); | ||
let product = multiply(sum, 2); | ||
let goodCode = format(product); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, much easier to understand!
Your Details
Your Name: Osagie Okoedo
Your City: Birmingham
Your Slack Name: Osagie Okoedo
Homework Details
Module: JavaScript
Week: 1