강의

멘토링

커뮤니티

Inflearn Community Q&A

rmeoandsk1237787's profile image
rmeoandsk1237787

asked

[Renewal] Introduction to JavaScript in Zero Seconds through Coding Self-Study

Create a self check-out

1아웃,2아웃,3아웃 질문입니다. 그리고 색 입히기

Written on

·

167

0

if (strike === 0 && ball === 0) {

      out++;

      $logs.append(`${value}:${out+0}아웃`,  document.createElement('br'))

    }

이렇게 코드를 작성해보았는데, 1아웃, 2아웃, 3아웃으로 정상 작동합니다.

 

 

여기서 {out+1}로 하면 2아웃 부터 작동하는데요, 이 원인은

  const numbers = []; // [1, 2, 3, 4, 5, 6, 7, 8, 9]

  for (let n = 0; n < 9; n += 1) {

    numbers.push(n + 1);

  }

의 numbers.push(n + 1); 때문인건가요? 

-------------------------------------------------------

글자 색 입히기

    if (strike === 0 && ball === 0) {

      out++;

      let outTxt = document.createElement('span');

      outTxt.style = 'color: red';

      outTxt.innerHTML = `${out+0}`+"아웃";

      $logs.append(`${value}:`, outTxt, document.createElement('br'))

    } else {

      let strikeTxt = document.createElement('span');

      strikeTxt.style = 'color: blue';

      strikeTxt.innerHTML = `${strike}`+"스트라이크";

      let ballTxt = document.createElement('span');

      ballTxt.style = 'color: green';

      ballTxt.innerHTML = `${ball}`+"볼";

      $logs.append(`${value}:`, strikeTxt, ballTxt, document.createElement('br'));

    }

    if (out === 3) {

      defeated ();

      return;

    }

 

아웃은 빨간색, 스트라이크는 파란색, 볼은 녹색으로 지정해 봤는데요, 맞는 방법일까요? 구동할 때는 오류 없이 잘 진행됐습니다.

 

javascript

Answer 1

1

zerocho님의 프로필 이미지
zerocho
Instructor

out++를 할 때 이미 1이 더해졌으므로 굳이 1 더 더할 필요가 없죠

네 컬러는 저렇게 해도 되는데 ballTxt.style.color = 'green'; 을 더 추천드립니다.

네 감사합니다. 질 높은 강의 감사합니다!

rmeoandsk1237787's profile image
rmeoandsk1237787

asked

Ask a question