Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.

Java script core 1 homework/week1/osagie #32

Open
wants to merge 31 commits into
base: master
Choose a base branch
from

Conversation

osagiestar
Copy link

Your Details

Your Name: Osagie Okoedo
Your City: Birmingham
Your Slack Name: Osagie Okoedo

Homework Details

Module: JavaScript
Week: 1

@osagiestar
Copy link
Author

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.

@osagiestar osagiestar closed this Jun 20, 2020
@osagiestar osagiestar reopened this Jun 20, 2020
Copy link

@pads pads left a 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;
Copy link

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;
Copy link

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;
Copy link

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;
Copy link

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);
Copy link

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).
Copy link

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)?

Copy link
Author

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}`;
Copy link

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;
Copy link

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//
Copy link

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);
Copy link

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!

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.

2 participants