๐Ÿ’ฌ ํŠน์ • ๊ตฌ๊ฐ„์—์„œ ๋ฉ˜ํŠธ ์ถœ๋ ฅ์ด ๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ - FRONTENDBOOTCAMP-13th/JS-07-7zzang-Arcade GitHub Wiki

๊ตฌ๋ถ„

  • ๋‚ ์งœ : 2025.05.19
  • ์ข…๋ฅ˜ : ๋ฒ„๊ทธ
  • ์ค‘์š”๋„ : ๐ŸŸก

๋ฌธ์ œ ์ƒํ™ฉ

  • ํŠน์ • ๊ตฌ๊ฐ„๋งˆ๋‹ค ๋ฉ˜ํŠธ๊ฐ€ ์ถœ๋ ฅ๋˜๋„๋ก ์„ค๊ณ„ํ–ˆ๋‹ค. ์ด๋•Œ ๊ฒŒ์ž„์—์„œ 17์ ์— ๋„๋‹ฌํ•˜๋ฉด ๋‹ค์Œ ๋ฉ˜ํŠธ๊ฐ€ ์ถœ๋ ฅ๋˜์–ด์•ผ ํ•œ๋‹ค.

    17: '๋ชธ์ด...๋ญ”๊ฐ€ ๊ฐ„์งˆ๊ฐ„์งˆํ•ด!'

    ํ•˜์ง€๋งŒ ๊ฒŒ์ž„์ด ์ข…๋ฃŒ๋˜๊ณ  Retry ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ๋‹ค์‹œ ์‹œ์ž‘ํ•œ ํ›„ 17์ ์— ๋„๋‹ฌํ•ด๋„ ๋ฉ˜ํŠธ๊ฐ€ ์ถœ๋ ฅ ๋˜์ง€ ์•Š๋Š”๋‹ค. ๋‹ค์Œ ๋‹จ๊ณ„๋ถ€ํ„ฐ๋Š” ๋‹ค์‹œ ์ถœ๋ ฅ ๋œ๋‹ค.


์›์ธ ๋ถ„์„

const shownWarnings = new Set<number>();

if (score === 17 && !shownWarnings.has(17)) {
showToast('๋ชธ์ด...๋ญ”๊ฐ€ ๊ฐ„์งˆ๊ฐ„์งˆํ•ด!');
shownWarnings.add(17);
}
  • ๋ฉ˜ํŠธ๋Š” ์ค‘๋ณตํ•ด์„œ ๋œจ์ง€ ์•Š๋„๋ก Set ๊ฐ์ฒด์ธ shownWarnings์— ๊ธฐ๋กํ•ด๋‘๊ณ , ํ•ด๋‹น ์ ์ˆ˜๊ฐ€ ๊ธฐ๋ก ๋˜๋Š”์ง€ ๊ฒ€์‚ฌํ•œ๋‹ค.

ํ•ด๊ฒฐ ๊ณผ์ •

  • ์ ์ˆ˜๊ฐ€ ์ž˜ ์ „๋‹ฌ ๋˜๋Š”์ง€ ํ™•์ธ

    console.log(score); ํ™•์ธํ–ˆ์„ ๋•Œ ์ ์ˆ˜๋Š” 17์ ์œผ๋กœ ์ถœ๋ ฅ ๋จ

  • ์กฐ๊ฑด์ด ๋งž์ง€ ์•Š๋Š”์ง€ ํ™•์ธ

    console.log(!shownWarings.has(17)); ๊ฐ’์ด false๊ฐ€ ๋œธ. ์ค‘๋ณต์ด ์•ˆ ๋˜๋Š”๋ฐ ์™œ Set์— 17์ด ์žˆ์ง€?

  • hownWarnings์— ๊ฐ’์ด ์ด๋ฏธ ์žˆ๋‹ค โ†’ ์ดˆ๊ธฐํ™” ๋ฌธ์ œ ํ™•์ธ

    resetGame() ํ•จ์ˆ˜ ๋‚ด์—์„œ console.log(shownWarings) ํ™•์ธ โ†’ Retry ์ „ํ›„์—๋„ Set์— 17์ด ๋‚จ์•„ ์žˆ์Œ ํ™•์ธ

โ‡’ ํ•ด๊ฒฐ : retry ์‹œ Set ์ดˆ๊ธฐํ™” ๊ฐ€๋Šฅํ•˜๋„๋กresetGame()ํ•จ์ˆ˜ ๋งˆ์ง€๋ง‰์— shownWarnings.clear();์ถ”๊ฐ€


๋ณด์™„ํ•  ์ 

  • Set ๊ฐ์ฒด๋Š” ****์ค‘๋ณต ๋ฐฉ์ง€์—๋Š” ์œ ์šฉํ•˜์ง€๋งŒ ์ „์—ญ ์ƒํƒœ๋กœ ์“ฐ๋Š” ๊ฒฝ์šฐ ๊ฒŒ์ž„ ์žฌ์‹œ์ž‘ ๋˜๋Š” ์ƒํƒœ ์ „ํ™˜ ์‹œ ๋ฐ˜๋“œ์‹œ ์ดˆ๊ธฐํ™”๊ฐ€ ํ•„์š”ํ•˜๋‹ค. clear()๋กœ ์ƒํƒœ๋ฅผ ์ดˆ๊ธฐํ™”ํ•˜๊ธฐ!
โš ๏ธ **GitHub.com Fallback** โš ๏ธ