GitHub - LearningTypeScript/projects: Hands-on real world projects that will help you exercise your knowledge of TypeScript.
Hands-on real world projects that will help you exercise your knowledge of TypeScript. - GitHub - LearningTypeScript/projects: Hands-on real world projects that will help you exercise your knowledg...
github.com
수정해야 할 첫 번째 코드 영역은 활동 할당 엔진입니다.
5-10명의 손님 규모의 그룹을 반복적으로 생성합니다.
각 그룹은 한 번에 특정 수의 그룹을 수용할 수 있는 활동으로 이동하도록 지시됩니다.
광대가 이것에 대해 너무 많이 망쳐놓은 것 같지는 않습니다.
그들은 대부분 몇 가지 타입 어노테이션을 제거하고 하나의 값을 변경했습니다.
진화하는, 암시적인 any를 피하기 위해 누락된 타입 어노테이션을 다시 추가하고,
잘못된 값을 수정해 주시겠습니까?
## 파일
- `index.ts`: 고칠 코드
- `solution.ts`: 솔루션
let remainingGuests = 20;
while (true) {
// Each group of guests will be size 5-10
const guestsToAssign = Math.floor(Math.random() * 5) + 5;
let activity : string; // Those were some nice type annotations you had here!
let capacity : number; // It'd be a shame if we ... *erased* them! 😈
let requiresSupplies : boolean;
switch (Math.floor(Math.random() * 5)) {
case 0:
activity = "balloon animals";
capacity = 5;
requiresSupplies = true;
break;
case 1:
activity = "face painting";
capacity = 1;
requiresSupplies = true;
break;
case 2:
activity = "juggling";
capacity = 3;
requiresSupplies = true;
break;
default:
activity = "dancing";
capacity = 10;
break;
}
console.log(`${guestsToAssign} of us will enjoy ${activity}.`);
for (let i = 0; i < guestsToAssign; i += capacity) {
console.log(`\t${capacity} will enter the ${activity} activity.`);
}
remainingGuests -= guestsToAssign;
if (remainingGuests < 0) {
break;
}
console.log(`We have ${remainingGuests} remaining guests to entertain.\n`);
}
console.log("\nAll done!");
export {};
변수의 타입을 지정하고, 잘못된 값을 고쳐주면 되는 간단한 문제
728x90
'Typescript > 러닝 타입스크립트 연습문제' 카테고리의 다른 글
| (3장) Primitive Cooking - 1. Ingredients (0) | 2023.04.06 |
|---|---|
| (2장) System of a Clown - 2. Clown Availability (0) | 2023.04.06 |
| (1장) The Typeinator - 3. Callbacks to Async Await (0) | 2023.04.05 |
| (1장) The Typeinator - 2. Prototypes to Classes (0) | 2023.04.05 |
| (1장) The Typeinator - 1. Syntactic Sugar (0) | 2023.04.05 |