Rock paper scissors



for(var getChoice=e=>{var r=prompt(`Player ${e}: `);return r.match(/^(r|p|s)/gi)?r.toLowerCase().slice(0,1):(alert("Invalid choice! Must be r(ock), p(aper) or s(cissors)"),getChoice(e))};;){var[a,b]=[getChoice("A"),getChoice("B")],code=["rpB","rsA","prA","psB","spA","srB","rr","pp","ss"].find(e=>e.startsWith(a+b)),reason=code.slice(0,2).split("").map(e=>("A"==code[2]&&e==a||"B"==code[2]&&e==b?e.toUpperCase():e)+{r:"ock",p:"aper",s:"cissors"}[e]);alert(`${code.slice(2)?`${("A"==code[2]?reason:reason.reverse()).join(` beat${code.match(/s.A|sB/)?"":"s"} `)}. `+`Player ${code.slice(2)} wins!`:"Tie!"}\n`)}