-
Notifications
You must be signed in to change notification settings - Fork 17
Samira w2 using ap is #62
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?
Conversation
// TODO return a promise using `fetch()` | ||
async function requestData(url) { | ||
try { | ||
const response = await fetch(url); |
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.
Nice job with the fetch
implementation.
async function fetchData(url) { | ||
try { | ||
const response = await fetch(url); | ||
if (!response.ok) { |
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.
Well done, checking the "HTTP errors" here.
}); | ||
export async function rollDieUntil(desiredValue) { | ||
let value; | ||
do { |
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.
Great thinking here. To make things more simpler (easy to read and less code), we can use while
loop without do
as follows:
...
while (value !== desiredValue) {
value = await rollDie();
}
...
@@ -15,20 +15,28 @@ import { rollDie } from '../../helpers/pokerDiceRoller.js'; | |||
|
|||
export function rollDice() { | |||
const dice = [1, 2, 3, 4, 5]; | |||
// TODO complete this function; use Promise.race() and rollDie() | |||
rollDie(1); // TODO placeholder: modify as appropriate | |||
return Promise.race(dice.map((die) => rollDice(die))); |
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.
- We are suppose to pass each
die
to therollDie(die)
method notrollDice(die)))
on line 18. The current solution will turn to a recursion (that a function calling itself), which leads to the error messageMaximum call stack size
in another word Stack overflow because we don't have a way (base case) to breakout of the recursive call. The final code on line 18 should look like thisreturn Promise.race(dice.map((die) => rollDie(die)));
.
@@ -7,20 +7,21 @@ async function getData(url) { | |||
const response = await fetch(url); |
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.
For exercise 5, I got this error message Something went wrong: fetch is not defined
when I run node ex5-vscDebug.js
in the terminal. I got the same error when I reviewed Konjit code.
Note: The issue is that we are using fetch()
method but we didn't import It or have access to it.
She told me the code works on her end, probably the problem is from my end.
@@ -16,29 +16,41 @@ Full description at: https://github.com/HackYourFuture/Assignments/blob/main/3-U | |||
url with `.shx`. There is no server at the modified url, therefore this |
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.
@samira313 Great job with the solutions. We are almost there. Let's try to make exercise 4 work. Once our exercise 4 is working, I will approve the homework. Let me know if you have any questions.
Hi Damilare David Oyediran,
Thank you for your detailed feedback! I have now fixed the issue in
exercise 4 by correctly passing die to rollDie(die) instead of
rollDice(die). The recursion issue is resolved, and the code works as
expected.
Also, regarding exercise 5, I am not encountering any errors. I have
attached a screenshot for verification. Please let me know if you need any
further modifications.
Thanks again for your guidance!
Best,
Samira Ahmadi
…On Tue, 11 Feb 2025 at 23:37, Damilare David Oyediran < ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In 3-UsingAPIs/Week2/assignment/ex1-programmerFun/index.js
<#62 (comment)>
:
> @@ -16,29 +16,41 @@ Full description at: https://github.com/HackYourFuture/Assignments/blob/main/3-U
url with `.shx`. There is no server at the modified url, therefore this
@samira313 <https://github.com/samira313> Great job with the solutions.
We are almost there. Let's try to make exercise 4 work. Once our exercise 4
is working, I will approve the homework. Let me know if you have any
questions.
—
Reply to this email directly, view it on GitHub
<#62 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BKWT54MNSGYWWTFPKLB6EUL2PJ3RXAVCNFSM6AAAAABWMWDYDCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDMMJQGI2DAMRRG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***
com>
|
Thank you for the update. Congratulations on completing Week 2 Homework. Great job. |
No description provided.