Menu
CoddyTech

요약: 테이블 셰이프 정의하기

Coddy Lua 여정의 Luau 소개 섹션에 포함된 레슨. 80개 중 46번째.

challenge icon

챌린지

중급

RAM을 알 수 없는 컴퓨터 한 대를 포함해 컴퓨터 두 대를 설명하세요.

  1. type Computer = {id: number, brand: string, ramInGB: number?}을 작성하고 workstation과 laptop을 Computer로 주석 처리하세요.
  2. local function specs(computer: Computer): string를 작성하세요. RAM을 알고 있으면 `{computer.brand} with {computer.ramInGB} GB of RAM`을 반환하고, 그렇지 않으면 `{computer.brand} with unknown RAM`을 반환하도록 하세요.
  3. specs(workstation)과 specs(laptop)을 출력하세요.

코드 실행을 누르세요. 출력에 Dell with 16 GB of RAM과 MacBook with unknown RAM이 표시됩니다.

직접 해보기

-- 1) type Computer = {...}

local workstation = {id = 1001, brand = "Dell", ramInGB = 16}
local laptop = {id = 1002, brand = "MacBook"}

-- 2) specs(computer: Computer): string
-- 3) 둘 다 specs를 출력하기
quiz icon실력 점검

이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.

Luau 소개의 모든 레슨

직접 연습해 보세요: 온라인 Luau 컴파일러