-
-
Notifications
You must be signed in to change notification settings - Fork 315
London | 26-ITP-January | Laura C | Sprint 2 | Structuring and Testing Data #960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bece12d
47250f9
52d7af4
c1206f8
2259714
268f2e1
b28bccd
dde33c9
4cb4a65
497ab63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,35 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
|
|
||
| // I predict this will throw a SyntaxError because | ||
| // the variable 'str' is declared twice inside the function. | ||
|
|
||
|
|
||
|
|
||
| // call the function capitalise with a string input | ||
| // interpret the error message and figure out why an error is occurring | ||
|
|
||
| function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
| // function capitalise(str) { | ||
| // let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| // return str; | ||
| // } | ||
|
|
||
|
|
||
| // =============> write your explanation here | ||
|
|
||
| // This code throws a SyntaxError: Identifier 'str' has already been declared. | ||
| // The function parameter is named 'str', and inside the function | ||
| // we try to declare another variable using 'let str'. | ||
| // JavaScript does not allow redeclaring a variable | ||
| // in the same scope. | ||
|
|
||
|
|
||
| // =============> write your new code here | ||
| function capitaliseFixed(str) { | ||
| let result = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return result; | ||
| } | ||
|
|
||
| console.log(capitaliseFixed("hello")); | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,27 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // I think this might print undefined | ||
| // The return statement looks separate from a + b, | ||
| // so maybe the function is not actually returning the sum. | ||
|
|
||
| function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
| // function sum(a, b) { | ||
| // return; | ||
| // a + b; | ||
| // } | ||
| //console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // The function has 'return;' on its own line. | ||
| // When JavaScript sees return, it stops the function immediately. | ||
| // That means 'a + b' never runs. | ||
| // Because nothing is returned, the function returns undefined. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function sum(a, b) { | ||
| return a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,9 @@ | |
| // Then when we call this function with the weight and height | ||
| // It should return their Body Mass Index to 1 decimal place | ||
|
|
||
| function calculateBMI(weight, height) { | ||
| function calculateBMI(weight, height) {const bmi = weight / (height * height); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you improve the indentation of the code in this script? |
||
| return bmi.toFixed(1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What type of value do you expect your function to return? A number or a string? |
||
| } | ||
| console.log(calculateBMI(70, 1.73)); | ||
|
|
||
| // return the BMI of someone based off their weight and height | ||
| } | ||
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.
It is possible to have a global variable and a parameter named
numin a script. For example,Can you find out why?