[ν•œμž…] πŸ“’Day9 Quiz

TKΒ·2023λ…„ 12μ›” 15일
0

[κ°•μ˜] ν•œμž… μ‹œλ¦¬μ¦ˆ

λͺ©λ‘ 보기
38/59

Quiz 1.

/*
[ 문제 μ†Œκ°œ ]
λ‹€μŒ μš”κ΅¬μ‚¬ν•­μ„ λ§Œμ‘±ν•˜λŠ” Pokemon 클래슀λ₯Ό μ™„μ„±ν•˜μ„Έμš”
- λ‹€μŒ 3개의 ν•„λ“œλ₯Ό κ°–μŠ΅λ‹ˆλ‹€.
  1. name ν•„λ“œλŠ” String νƒ€μž…μ΄λ©° Publicμž…λ‹ˆλ‹€.
  2. skill ν•„λ“œλŠ” String νƒ€μž…μ΄λ©° Public μž…λ‹ˆλ‹€.
  3. type ν•„λ“œλŠ” String νƒ€μž…μ΄λ©° ReadOnly(읽기 μ „μš©)ν•„λ“œ μž…λ‹ˆλ‹€.
- λ‹€μŒ 2개의 λ©”μ„œλ“œλ₯Ό κ°–μŠ΅λ‹ˆλ‹€.
  1. getName λ©”μ„œλ“œλŠ” name ν•„λ“œμ˜ 값을 λ°˜ν™˜ν•©λ‹ˆλ‹€.
  2. setSkill λ©”μ„œλ“œλŠ” String νƒ€μž…μ˜ λ§€κ°œλ³€μˆ˜λ₯Ό λ°›μ•„ skill ν•„λ“œμ˜ 값을 μ—…λ°μ΄νŠΈ ν•©λ‹ˆλ‹€.
*/

/* [Quiz] κ΅¬ν˜„ μ‹œκ·Έλ‹ˆμ³λ₯Ό μ™„μ„±ν•˜μ„Έμš” */
class Pokemon {}

/* [Test] μ—¬κΈ°λΆ€ν„°λŠ” 정닡을 μ²΄ν¬ν•˜κΈ° μœ„ν•œ μš©λ„λ‘œ μˆ˜μ •ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€ */
const pikachu = new Pokemon("ν”ΌμΉ΄μΈ„", "백만볼트", "μ „κΈ°");
pikachu.getName();
pikachu.setSkill("천만볼트!");

λ‹΅μ•ˆ (ν‹€λ¦Ό)

class Pokemon {
  name: string;
  skill:string;
  readonly type:string;
  constructor(name:string, skill:string, type:string){
    this.name=name;
    this.skill=skill;
    this.type=type;
  }
  getName():string{
    return this.name;
  }
  setSkill(skill:string):string{
    return `${this.skill}` //❌
  }
}

λͺ¨λ²•λ‹΅μ•ˆ

class Pokemon {
  constructor(public name: string, public skill: string, readonly type: string) {}

  getName(): string {
    return this.name;
  }

  setSkill(skill: string): void {
    this.skill = skill;
  }
}
profile
μ‰¬μš΄κ²Œ 쒋은 FE개발자😺

0개의 λŒ“κΈ€