Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

samira313
Copy link

No description provided.

@ddoyediran ddoyediran self-assigned this Feb 9, 2025
// TODO return a promise using `fetch()`
async function requestData(url) {
try {
const response = await fetch(url);

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) {

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 {

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)));
Copy link

@ddoyediran ddoyediran Feb 11, 2025

Choose a reason for hiding this comment

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

  1. We are suppose to pass each die to the rollDie(die) method not rollDice(die))) on line 18. The current solution will turn to a recursion (that a function calling itself), which leads to the error message Maximum 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 this return Promise.race(dice.map((die) => rollDie(die)));.

@@ -7,20 +7,21 @@ async function getData(url) {
const response = await fetch(url);

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

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.

@samira313
Copy link
Author

samira313 commented Feb 12, 2025 via email

@ddoyediran
Copy link

Thank you for the update. Congratulations on completing Week 2 Homework. Great job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants