javascript - How to unshorten this js code -


this question has answer here:

i trying understand code of this tic-tac-toe (30 lines of code) game , encountered strange me notation of js.

  1. t[id] ? ai() : move(id, 'ai');
  2. !checkend() ? (role == 'player') ? ai() : null : reset()

i know shortened version of if-statement, don't know how convert it.

thanks in advance.

this ternary operator in javascript.

t[id] ? ai() : move(id, 'ai'); 

translates to:

if (t[id])     ai(); else     move(id, 'ai'); 

and !checkend() ? (role == 'player') ? ai() : null : reset() to:

if (!checkend())     if (role == 'player')         ai();     else         ; else     reset(); 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -