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

London Class 9 - Farzaneh Haghani - JavaScript - Week 1 - #443

Open
farzaneh-haghani wants to merge 12 commits into
CodeYourFuture:masterfrom
farzaneh-haghani:master
Open

London Class 9 - Farzaneh Haghani - JavaScript - Week 1#443
farzaneh-haghani wants to merge 12 commits into
CodeYourFuture:masterfrom
farzaneh-haghani:master

Conversation

@farzaneh-haghani

@farzaneh-haghani farzaneh-haghani commented Nov 24, 2022

Copy link
Copy Markdown

Your Details

  • Your Name: Farzaneh Haghani
  • Your City: London
  • Your Slack Name: Farzaneh Haghani

Homework Details

  • Module: JavaScript
  • Week: 1

Notes

  • What did you find easy? Find syntax errors

  • What did you find hard? 8 ball magic (It wasn't hard but it was unclear that how it works).

  • What do you still not understand? Nothing

  • Any other notes? No


View rendered README.md
View rendered exercises/B-hello-world/README.md

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

Thanks for hardworking .

@JDysiewicz JDysiewicz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, well done! Hopefully the comment about 8 ball cleared things up a little.

@@ -1,3 +1,5 @@
// Start by creating a variable `greeting`

var greeting = "Hello world";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

try to always use const to declare variables; let can be used too but only use if if the variable needs redefining at some point (normally, this won't be the case, which is why we prefer const).

var is now outdated, so try to avoid using it :P

console.log(message);
var myName = "Daniel";
var message = myName.length;
console.log(`My name is ${myName} and my name is ${message} characters long`);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice use of a template string!

@@ -1,3 +1,5 @@
const name = " Daniel ";

message = name.trim(" ");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

almost - variables in JS need declaring by prefixing the variable name with let or const. This effectively tells JS "Hey, every time you see variableName from this point onwards, it's actually talking about this variable"

Comment on lines +2 to +4
function divide(x, y) {
return x / y;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You didn't have to account for this, but what would happen if y = 0 was passed in and you end up with x / 0? try doing that in JS and see what happens. With knowledge of conditionals (like if statements) how would you prevent that from occurring?

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. I updated

Comment thread extra/2-piping.js
Comment on lines +37 to +39
let result = add(startingValue, 10);
result = multiply(result, 2);
let goodCode = format(result);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yup this is certainly better; one more improvement that could be made here though is to use const instead to declare multiple variables e.g.

const addResult = add(startingValue, 10)
const multiplyResult = multiply(addResult, 2)
const formattedResult = format(multiplyResult)

A nice rule of thumb to go by with code-style is to always err on the more verbose side (i.e. it's almost always better to be more explicit about your intentions). The code will give the same result either way, so all your code-style is for is for other developers who'll look at your code, and in that case it's better to make your intentions very obvious.

Comment thread extra/3-magic-8-ball.js Outdated
Comment on lines +78 to +79
let firstItem = Math.floor(Math.random() * 4);
let secondItem = Math.floor(Math.random() * 5);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So Math.random() returns a random number between 0 and 1 (e.g. 0.6291232). Therefore, when trying to get random integers (i.e. for indexing an array) we tend to multiply by array.length, then get the floor. This means that we generate a random number between 0 and array.length, then get the floor (round down to nearest integer). This way, we generate a random number between 0 - array.length, then get the floor, such that we are guaranteed a random number that is either 0,1,2,3...array.length-1 (remember, the last index of an array is it's length -1 as we start at 0).

You could avoid hard coding the 4 or 5 here by getting the array lengths, but that's beyond what is expected here

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. updated.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants