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

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

Copy
const target = start.childNodes[goTop] ? start.childNodes[goTop].childNodes[0].childNodes[goLeft] : null;
Copy
const dir = temp_block.direction + 1 < 4 ? temp_block.direction + 1 : 0;

답변 2개

채택된 답변
+20 포인트
Copy
//const target = start.childNodes[goTop] ? start.childNodes[goTop].childNodes[0].childNodes[goLeft] : null;

 

let target = null;

if (start.childNodes[goTop] != null) {

    target = start.childNodes[goTop].childNodes[0].childNodes[goLeft];

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

 

let dir = 0;

if (temp_block.direction + 1 < 4) {

    dir = temp_block.direction + 1;

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

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

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으로 대입한다 입니다.

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

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

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

로그인
🐛 버그신고