generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 239
Manchester | 25-ITP-Sep | Hani Sadah| Sprint 2 | Coursework/sprint 2 #836
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
Open
HANISADAH
wants to merge
16
commits into
CodeYourFuture:main
Choose a base branch
from
HANISADAH:coursework/sprint-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
15dadf1
Answering the task
HANISADAH c642719
Answering the task
HANISADAH f91a49c
Answering the task
HANISADAH a33f384
Answering the task 1
HANISADAH a734ad2
Answering the task
HANISADAH 336d1b4
Answering the task 1 bmi
HANISADAH 11a298c
Answering the task 2 cases
HANISADAH c14e9d7
Answering the task 3
HANISADAH 97da7db
Answering the task time-format
HANISADAH 23ddb39
Answering the task
HANISADAH 2f8ccfb
Merge branch 'CodeYourFuture:main' into coursework/sprint-2
HANISADAH 25bda16
deleted medina.js
HANISADAH db3249a
Updating the task
HANISADAH e03cac5
updating the task's answer
HANISADAH cb2de15
updating the answer
HANISADAH 6941206
Updating the answer
HANISADAH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,22 @@ | ||
|
|
||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // =============> I predict that we will not need to write let in line 8 as str is already declared | ||
| // as an argument within the function captialise. | ||
|
|
||
| // 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; | ||
| // } | ||
|
|
||
| // capitalise ('hello'); | ||
| //==============> A syntaxError occurred as 'str' is being cleared. | ||
|
|
||
|
|
||
| function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your new code here | ||
| console.log (capitalise ('hello')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,33 @@ | ||
|
|
||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // =============> write your prediction here | ||
| // =============> I believe that the function convertToPercentage is not mentioned in the console.log statement. | ||
| // Declaring the const decimalNumber is unnecessary as it is already declared as a parameter within the function convertToPercentage. | ||
|
|
||
| // Try playing computer with the example to work out what is going on | ||
|
|
||
| function convertToPercentage(decimalNumber) { | ||
| const decimalNumber = 0.5; | ||
| const percentage = `${decimalNumber * 100}%`; | ||
| // function convertToPercentage(decimalNumber) { | ||
| // const decimalNumber = 0.5; | ||
| // const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
| // return percentage; | ||
| //} | ||
|
|
||
| console.log(decimalNumber); | ||
| // console.log(decimalNumber); | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> A syntaxError occurred saying decimalNumber is already declared. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
|
|
||
| function convertToPercentage(num) { | ||
|
|
||
| const percentage = `${num * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
|
|
||
| console.log(convertToPercentage(0.1)); | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,26 @@ | ||
|
|
||
|
|
||
| // Predict and explain first BEFORE you run any code... | ||
|
|
||
| // this function should square any number but instead we're going to get an error | ||
|
|
||
| // =============> write your prediction of the error here | ||
| // =============> The num parameter should be mentioned inside the function square instead of the number 3. | ||
| // then it should be called as square (3) in the console.log statement. | ||
|
|
||
| function square(3) { | ||
| return num * num; | ||
| } | ||
| //function square(3) { | ||
| //return num * num; | ||
| //} | ||
|
|
||
| // =============> function square(3) syntaxError: Unexpected number. | ||
| // =============> 3 wasn't expected... instead a declaration like 'num' was expected. | ||
|
|
||
| // =============> write the error message here | ||
|
|
||
| // =============> explain this error message here | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
| function square(num) { | ||
| return num * num; | ||
| } | ||
|
|
||
|
|
||
| console.log(square(3)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,21 @@ | ||
|
|
||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // =============> In line 6, instead of console.log printing the result of multiply(10, 32), return a*b would be better | ||
| //because the console.log would only print a*b. | ||
|
|
||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
| //function multiply(a, b) { | ||
| //console.log(a * b); | ||
| //} | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
| //console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> After running the code, we got 'the result of multiplying 10 and 32 is undefined' | ||
| // as the multiply parameters weren't considered as parameters inside the function multiply. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function multiply(a, b) { | ||
| return a * b; | ||
| } | ||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // =============> SyntaxError will occur due to putting a semicolon after return. | ||
|
|
||
| function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| return a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> unlike the expectation that the code runs without error as 'the sum of 10 and 32 is undefined'. | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| // we needed just to remove the semicolon after return statement and to bring up the a+b expression side by side with return. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,34 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Predict the output of the following code: | ||
| // =============> Write your prediction here | ||
| // =============> The code will return 3 as a string first, but after calling the getLastDigit function, | ||
| // it will not return anything because every number based will be converted to string. | ||
|
|
||
| const num = 103; | ||
| //const num = 103; | ||
|
|
||
| function getLastDigit() { | ||
| return num.toString().slice(-1); | ||
| } | ||
| //function getLastDigit() { | ||
| // return num.toString().slice(-1); | ||
| //} | ||
|
|
||
| console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
| console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
| console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
| //console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
| //console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
| //console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
|
|
||
| // Now run the code and compare the output to your prediction | ||
| // =============> write the output here | ||
| // Explain why the output is the way it is | ||
| // =============> write your explanation here | ||
| // =============> The last digit of 42 is 3 three times. | ||
| // the prediction was close but not accurate, the case is that the parameter num needs to be | ||
| //the function instead of const num = 103. | ||
| // =============> | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
|
|
||
| function getLastDigit(num) { | ||
| return num.toString().slice(-1); | ||
| } | ||
|
|
||
| console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
| console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
| console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
| // This program should tell the user the last digit of each number. | ||
| // Explain why getLastDigit is not working properly - correct the problem | ||
| // parameter num needs to be with the getLastDigit function instead of const num=103. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 type of value do you expect your function to return? A number or a string?
Does your function return the type of value you expect?
Different types of values may appear identical in the console output, but they are represented and treated differently in the program. For example,
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.
I expect the function will return a number and it does return a number.
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.
Can you look up how to check if a value is a number in JavaScript, and then apply the technique to verify your expectation?