Ad
Fundamentals
Strings
Code
Diff
  • const reverseStr = string => string.split('').reverse().join('')
    • const reverseStr = s => {
    • let ss = "";
    • for (let i = s.length-1; i >= 0; i--) {
    • ss += s[i];
    • }
    • return ss;
    • }
    • console.log(reverseStr("Lorem ipsum dolor sit amet!"))
    • const reverseStr = string => string.split('').reverse().join('')
Code
Diff
  • function dumbRockPaperScissors(player1, player2) {
      let res = "Player 1 wins";
      
      if(
        player1 === player2
      ){
        res = "Draw"
      } else if(
        player1 == "Rock" && player2 == "Paper" ||
        player1 == "Scissors" && player2 == "Rock" ||
        player1 == "Paper" && player2 == "Scissors"
      ) {
        res = "Player 2 wins";
      }
      return res;
    }
    • function dumbRockPaperScissors(player1, player2) {
    • if(player1 == "Rock" && player2 == "Paper"){
    • return "Player 2 wins";
    • let res = "Player 1 wins";
    • if(
    • player1 === player2
    • ){
    • res = "Draw"
    • } else if(
    • player1 == "Rock" && player2 == "Paper" ||
    • player1 == "Scissors" && player2 == "Rock" ||
    • player1 == "Paper" && player2 == "Scissors"
    • ) {
    • res = "Player 2 wins";
    • }
    • else if(player1 == "Rock" && player2 == "Scissors" ){
    • return "Player 1 wins";
    • }
    • else if(player1 == "Scissors" && player2 == "Paper"){
    • return "Player 1 wins";
    • }
    • else if(player1 == "Scissors" && player2 == "Rock"){
    • return "Player 2 wins";
    • }
    • else if(player1 == "Paper" && player2 == "Scissors"){
    • return "Player 2 wins";
    • }
    • else if(player1 == "Paper" && player2 == "Rock"){
    • return "Player 1 wins";
    • }
    • else if(player1 == "Paper" && player2 == "Paper"){
    • return "Draw";
    • }
    • else if(player1 == "Rock" && player2 == "Rock"){
    • return "Draw";
    • }
    • else if(player1 == "Scissors" && player2 == "Scissors"){
    • return "Draw";
    • }
    • return res;
    • }