테스트 사이트 - 개발 중인 베타 버전입니다

삼항연산자 if else문 채택완료

흐어어어어 3년 전 조회 2,118

안녕하세요 고수님들! 아직 초보라 많이 배우는 중인 주니어입니다! 다른게 아니라 공부하던 중 삼항연산자가 나왔는데 이것을 제이쿼리 ifelse문으로 다시 해석하고 싶어서 여쭤봅니다! 혹시 아시는 고수님들 계시면 해석 부탁드립니다!! 감사합니다

 

</p>

<p>const target = start.childNodes[goTop] ? start.childNodes[goTop].childNodes[0].childNodes[goLeft] : null;</p>

<p>

 

</p>

<p>const dir = temp_block.direction + 1 < 4 ? temp_block.direction + 1 : 0;</p>

<p>

댓글을 작성하려면 로그인이 필요합니다.

답변 2개

채택된 답변
+20 포인트
3년 전

</p>

<p>//const target = start.childNodes[goTop] ? start.childNodes[goTop].childNodes[0].childNodes[goLeft] : null;</p>

<p> </p>

<p>let target = null;</p>

<p>if (start.childNodes[goTop] != null) {</p>

<p>    target = start.childNodes[goTop].childNodes[0].childNodes[goLeft];</p>

<p>}</p>

<p>

 

</p>

<p>//const dir = temp_block.direction + 1 < 4 ? temp_block.direction + 1 : 0;</p>

<p> </p>

<p>let dir = 0;</p>

<p>if (temp_block.direction + 1 < 4) {</p>

<p>    dir = temp_block.direction + 1;</p>

<p>}</p>

<p>

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

const target = start.childNodes[goTop] ? start.childNodes[goTop].childNodes[0].childNodes[goLeft] : null;

target 값은 start.childNodes[goTop] 값이 있으면 start.childNodes[goTop].childNodes[0].childNodes[goLeft] 값을 대입하고 start.childNodes[goTop] 값이 없으면 null 값을 대입 한다 입니다.

 

const dir = temp_block.direction + 1 < 4 ? temp_block.direction + 1 : 0;

dir 값은 (temp_block.direction + 1) 값이 < 4 4보다 작으면 (temp_block.direction + 1)의 값을 대입하고 그 외에는 0으로 대입한다 입니다.

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인