Typescript/러닝 타입스크립트 연습문제

(3장) Primitive Cooking - 1. Ingredients

띵킹 2023. 4. 6. 21:00

 

https://github.com/LearningTypeScript/projects/tree/main//projects/unions-and-literals/primitive-cooking/01-ingredients

 

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

수정해야 할 첫 번째 코드 영역은 재료 플래너입니다. 
나는 이것을 식사에 사용할 샐러드 채소와 드레싱의 종류를 인쇄하는 데 사용합니다.

이번에도 런타임 코드가 제대로 작동합니다. 수정해야 하는 것은 타입 어노테이션일 뿐입니다.

## 파일
index.ts: 여기에서 타입 어노테이션 수정
solution.ts: 솔루션 코드
// Please correct any type annotation problems here! ✨
let arugula: number | undefined;
let dressing: string;
let lettuce: number | undefined;
let mealDate: Date;

arugula = 2;
dressing = "honey dijon";
lettuce = undefined;
mealDate = new Date("September 13, 2021");

console.log(`We're starting on ${mealDate} with a dressing of ${dressing}.`);

if (arugula) {
	console.log(`There are ${arugula} arugula serving(s) for this first meal.`);
}

if (lettuce) {
	console.log(`There are ${lettuce} lettuce serving(s) for this first meal.`);
}

arugula = undefined;
dressing = "balsamic vinaigrette";
lettuce = 1;
mealDate = new Date("March 13, 2022");

console.log(`Next up, a ${mealDate} meal with a dressing of ${dressing}.`);

if (arugula) {
	console.log(`This time, there are ${arugula} arugula serving(s).`);
}

if (lettuce) {
	console.log(`This time, there are ${lettuce} lettuce serving(s).`);
}

export {};

이번에도 간단한 타입 수정 문제였다

728x90