Putting it together · 모아보기
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Putting it together
- Real programs combine variables, loops, functions, arrays and objects.
- A
for...ofloop reads each item of an array directly — no index needed.
한국어
통합하기
- 실제 프로그램은 변수, 루프, 함수, 배열, 객체를 결합합니다.
- 인덱스가 필요 없이 배열의 각 항목을 직접 읽는
for...of루프입니다.
function total(nums) {
let t = 0;
for (const n of nums) {
t = t + n;
}
return t;
}
console.log(total([4, 8, 6])); // → 18
Explore · 탐색하기
for...of builds the total · for...of는 합계를 계산합니다
for...of reads each item directly. Watch t add them up, one at a time. · for...of는 각 항목을 직접 읽습니다. t가 하나씩 더하며 합계하는 것을 확인하세요.
English
Searching and counting
- Loop through the array, and keep a counter (or a flag) as you go.
한국어
탐색 및 카운팅
- 배열을 순환하면서 카운터(또는 플래그) 를 유지하세요.
function countAbove(nums, limit) {
let count = 0;
for (const n of nums) {
if (n > limit) {
count++;
}
}
return count;
}
console.log(countAbove([3, 7, 2, 8], 4)); // → 2
English
Common mistakes
- Build in small steps and use
console.logto check as you go. - Keep the HTML, CSS and JavaScript doing their own jobs.
한국어
흔한 실수
- 작은 단계로 구축하고, 진행하면서
console.log을 사용하여 확인하세요. - HTML, CSS, JavaScript가各自의 역할을 수행하도록 하세요.
English
Now you try
- Write each function using a loop.
- Press Check answer to test it.
한국어
이제 직접 해보기
- 루프를 사용하여 각 함수를 작성하세요.
- 답안 확인을 눌러 테스트해 보십시오.
Write a function total(nums) that returns the sum of every number in the array nums. · 함수 total(nums)를 작성하여 배열 nums의 모든 숫자의 합을 반환하도록 하세요.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Write a function biggest(nums) that returns the largest value in the array. · 함수 biggest(nums)를 작성하여 배열 내의 가장 큰 값을 반환하도록 하세요.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Write a function countAbove(nums, limit) that returns how many numbers are greater than limit. · 함수 countAbove(nums, limit)를 작성하여 숫자가 limit보다 큰 개수를 반환하도록 하세요.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.