Repository navigation
London | 25-ITP-Sep; | Rawan Almutairi | Sprint 3 | JavaScript exercises #1644
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
Rawan0-0
wants to merge
3
commits into
CodeYourFuture:main
Choose a base branch
from
Rawan0-0:sprint-3-m
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.
+255
−40
Open
Changes from all commits
Commits
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
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,40 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // =============> write your prediction here | ||
|
|
||
| // =============> write your prediction here | ||
| //this has the same issue as the one I encountered in the previous example. decimalNumber is declared twice | ||
| //so I'm expecting a syntaxError, the identifier decimalNumber has been declared twice | ||
| // Try playing computer with the example to work out what is going on | ||
|
|
||
| //function convertToPercentage(decimalNumber) { | ||
| // const decimalNumber = 0.5; | ||
| // const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| // return percentage; | ||
| //} | ||
|
|
||
| //console.log(decimalNumber); | ||
|
|
||
| // =============> write your explanation here | ||
| //the solution is to make the variable declared only once as a parameter | ||
| // and than remove the declaration from line 11 by removing let and reassigning its value | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
|
|
||
| function convertToPercentage(decimalNumber) { | ||
| const decimalNumber = 0.5; | ||
| decimalNumber = 0.5; | ||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
|
|
||
| console.log(decimalNumber); | ||
|
|
||
| // =============> write your explanation here | ||
| console.log(convertToPercentage(0.8)); | ||
| //ok I had to correct my solution because a reference error is caused by | ||
| //calling a parameter that only identified inside the function | ||
| //the solution would be to change line 18 to call the function and input | ||
| //input the value we want to convert because no point of declaring identifier twice | ||
| //what I notice by connicting both examples: the previous example the identifier was declared twice inside the function which caused a syntaxError | ||
| //in this example there is also declaring identifier that only identified inside a function , so the program doesn't recognise it which cause | ||
| //cause a reference error | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here |
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,29 @@ | ||
|
|
||
| // 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 | ||
| //ok, according to javaScript rules or convention for variables, we can't start with a number | ||
| //I'm expecting a syntaxErrror because its against javaScript rules | ||
|
|
||
| function square(3) { | ||
| return num * num; | ||
| } | ||
| //function square(3) { | ||
| // return num * num; | ||
| //} | ||
|
|
||
| // =============> write the error message here | ||
|
|
||
| //SyntaxError: Unexpected number | ||
| //not bad for a prediction-_- | ||
| // =============> explain this error message here | ||
|
|
||
| //it means javaCript can't identify what this number represent | ||
| //it's not part of the built in rules | ||
| // Finally, correct the code to fix the problem | ||
|
|
||
| //we just change number 3 to a the word three and assign its value to num | ||
| // =============> write your new code here | ||
| function square(three) { | ||
| num = three; | ||
| return num * num; | ||
| } | ||
| console.log(square(4)); | ||
|
|
||
|
|
||
| //so far this sprint is easy-_- |
Empty file.
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,26 @@ | ||||||
| // Predict and explain first... | ||||||
|
|
||||||
| // =============> write your prediction here | ||||||
| //inside the function console.log doesn't have the value of a and b parameters | ||||||
| //if I think like the computer than I will see a function declared with parameters a and b | ||||||
| //next line I will see a print function of the parameters a and b with operator * | ||||||
| //I'm not a computer but I think if I was , I will print a * b | ||||||
| //than I will call the multiply function again to show the message | ||||||
| //The result of multiplying 10 and 32 is 320 | ||||||
| //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 | ||||||
| //ok, I was werong in my prediction about console.log not using the parameters value outside the function, which I correctr my understanduing Headers.apply | ||||||
| //what happens is the result is printed twice, the solution would be to remove the console.log from inside the function and use return instead while keeping console.log function call or in line 15 | ||||||
|
|
||||||
| // Finally, correct the code to fix the problem | ||||||
| // =============> write your new code here | ||||||
| // ===========> write your new code here | ||||||
| function multiply(a, b) { | ||||||
| return (a, b); | ||||||
|
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.
Suggested change
I think this is still is still incorrect. It should be return a * b; to be able to perform the multiplication. |
||||||
| } | ||||||
|
|
||||||
| 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,29 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| //ok, I predict a syntaxError: a and b are not identified, and I think this because | ||
| //because the use of return function, I haven't encountered a similar case but I think it has to do | ||
| //with what the return function do, it returns the values of the parameters so | ||
| //so when a and b are used there is an issue happining but I can't say what because I don't have the information | ||
| //function sum(a, b) { | ||
| //return; | ||
| //a + b; | ||
|
|
||
| function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| } | ||
| //} | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
| //console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| //ok I see this error "The sum of 10 and 32 is undefined" | ||
| //I had to search what return do that cause this to be able to explain it correctly. | ||
| // this is my explaination before searching " I'm suspecting the error is caused by the return function returning the parameters values so when we use a + b; the program doesn't find what we are looking for because it was already returned" | ||
| //after searching I understand it caused becaused return means exiting the function , so line 10 will never be excuted | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| //the correction would be to include a + b inside return function so the value become identified | ||
| // ===========> write your new code here | ||
|
|
||
| function sum(a, b) { | ||
| return a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(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
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
Oops, something went wrong.
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.
Hi I you've done a great work identifying the error. To be more precise,
The real problem here is that str is declared twice: once as the function parameter
once again with let str = ...