Skip to content
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

5번 6번 문제 pr 요청입니다. #33

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions jinyoung/실습/13장/5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const weather = ["맑은 날씨", "태풍"];

const value = Math.round(Math.random() * 1);

function goSchool() {
return new Promise((result) => {
result("집에서 출발");
});
}

function arriveSchool() {
Copy link
Contributor

@K-0joo K-0joo Oct 1, 2022

Choose a reason for hiding this comment

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

앗 진영님 5번 문제가
2번 문제가

Promise를 사용해서,
1.집에서 출발한 뒤,
2. 30분뒤에 학교에 도착했고,
3. 그 후에 하리보를 먹었다.
4. 그리고 교수님이 오셔서 수업을 들었다.
를 출력하는(나타내는) 코드를 작성해보세요.

이거에 대해서 async/await 하는거에요! 어..slack 보니까 아닌가 둘 중 하나 선택이었나요? 헷갈리네요..

Copy link
Contributor Author

@jinyoung234 jinyoung234 Oct 1, 2022

Choose a reason for hiding this comment

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

제대로 못봤나 봐여 ㅜ 고쳐 오겠습니다

return new Promise((result, reject) => {
if (weather[value] === "맑은 날씨") {
setTimeout(() => {
setTimeout(() => {
result("학교에 도착");
}, 1000 * 60 * 30);
}, 1000 * 60 * 30);
} else if (weather[value] === "태풍") {
reject();
}
});
}

function eatHaribo() {
return new Promise((result) => {
result("하리보 냠냠쩝쩝");
});
}

function studyWithProfessor() {
return new Promise((result) => {
result("수업 시작");
});
}

goSchool()
.then((sequence1) => {
console.log(sequence1);
return arriveSchool("맑은 날씨");
})
.then((sequence2) => {
console.log(sequence2);
return eatHaribo();
})
.then((sequence3) => {
console.log(sequence3);
return studyWithProfessor();
})
.then((sequence4) => {
console.log(sequence4);
})
.catch((err) => {
console.log("자휴 후 집 도착");
});
50 changes: 50 additions & 0 deletions jinyoung/실습/13장/6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const weather = ["맑은 날씨", "태풍"];

const value = Math.round(Math.random() * 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

오, 이렇게 간단하게 가능하다니 진영님 최고 짱~ 👍


function goSchool() {
return new Promise((resolve) => {
resolve("집에서 출발");
});
}

function arriveSchool() {
return new Promise((resolve, reject) => {
if (weather[value] === "맑은 날씨") {
setTimeout(() => {
setTimeout(() => {
resolve("학교에 도착");
}, 1000 * 60 * 30);
}, 1000 * 60 * 30);
} else if (weather[value] === "태풍") {
reject();
}
});
}

function eatHaribo() {
return new Promise((resolve) => {
resolve("하리보 냠냠쩝쩝");
});
}

function studyWithProfessor() {
return new Promise((resolve) => {
resolve("수업 시작");
});
}

async function sequence() {
const sequence1 = await goSchool();
console.log(sequence1);
const sequence2 = await arriveSchool();
console.log(sequence2);
const sequence3 = await eatHaribo();
console.log(sequence3);
const sequence4 = await studyWithProfessor();
console.log(sequence4);
}

sequence().catch((err) => {
console.log("자휴 후 집 도착");
});