Ad
Code
Diff
  • function dumbRockPaperScissors(player1, player2) {
      let condition = {
        Scissors: "Paper",
        Rock: "Scissors",
        Paper: "Rock",
      };
      
      switch (true) {
        case player2 === condition[player1]: return "Player 1 wins";
        case player1 === condition[player2]: return "Player 2 wins";
        case player1 === player2: return "Draw";
      }
    }
    • function dumbRockPaperScissors(player1, player2) {
    • let condition = {
    • Scissors: 'Paper',
    • Rock: 'Scissors',
    • Paper: 'Rock',
    • }
    • if (player2 === condition[player1]) {
    • return "Player 1 wins";
    • }
    • if (player1 === condition[player2]) {
    • return "Player 2 wins";
    • }
    • if (player1 === player2) {
    • return "Draw";
    • let condition = {
    • Scissors: "Paper",
    • Rock: "Scissors",
    • Paper: "Rock",
    • };
    • switch (true) {
    • case player2 === condition[player1]: return "Player 1 wins";
    • case player1 === condition[player2]: return "Player 2 wins";
    • case player1 === player2: return "Draw";
    • }
    • }
Strings

Create a function that takes a string and returns true if no character appears twice, false otherwise.

function isUnique(string) {
  let knownChars = "";
  for (let char of string) {
    if (!knownChars.includes(char)) {
      knownChars += char;
    } else {
      return false;
    }
  }
  return true;
}