Menu
Coddy logo textTech

요약 - 스코프 퍼즐

Coddy Lua 여정의 Fundamentals 섹션에 포함된 레슨 — 90개 중 87번째.

challenge icon

챌린지

쉬움

다음 코드 스니펫을 분석하고 각 print 문에 의해 무엇이 출력될지 예측하세요. 예측값을 저장할 변수를 생성한 다음 올바른 순서대로 출력하세요.

분석할 코드는 다음과 같습니다:

gameScore = 100

function updateScore()
    local gameScore = 250
    print(gameScore)
end

do
    local gameScore = 75
    updateScore()
    print(gameScore)
end

print(gameScore)

예측값을 저장할 세 개의 변수를 생성하세요:

  • firstOutput - 첫 번째 print 문이 출력할 내용
  • secondOutput - 두 번째 print 문이 출력할 내용
  • thirdOutput - 세 번째 print 문이 출력할 내용

그런 다음 세 개의 예측값을 순서대로 각 줄에 하나씩 출력하세요.

직접 해보기

-- 예측값을 저장할 변수를 생성합니다
local firstOutput = -- TODO: 첫 번째 print 문을 분석하고 예측된 값을 할당하세요
local secondOutput = -- TODO: 두 번째 print 문을 분석하고 예측된 값을 할당하세요
local thirdOutput = -- TODO: 세 번째 print 문을 분석하고 예측된 값을 할당하세요

-- 예측값을 순서대로 출력합니다
print(firstOutput)
print(secondOutput)
print(thirdOutput)

Fundamentals의 모든 레슨