#NoCode to #SomeCode

I decided to begin learning to code in ReactJS to help me understand the background for ThunkableX and to potentially one day begin creating extensions and perhaps full fledged React Native apps.

Tonight I finished a Rock/Paper/Scissors game. Tough stuff, it’s definitely not block code. The toughest for me is the syntax. remembering to include a ‘()’, ‘,’ always using camelCase, or remembering how to call a function (the right way and to choose the right type).

Code below


const getUserChoice = userInput =>{
  userInput = userInput.toLowerCase();
  if(userInput ==='rock' || userInput==='paper' || userInput ==='scissors' || userInput === 
    'bomb') {return userInput;} 
  else{console.log('invalid choice, try again!')};
};

function getComputerChoice () {
  var randomNumber = Math.floor(Math.random() * 3);
  switch (randomNumber){
    case 0: 
      return 'rock';
    case 1:
      return 'paper';
    case 2: 
      return 'scissors';
  };
  }

function determineWinner (userChoice, computerChoice){
  if (userChoice==='bomb'){
    return 'USER Killed that shit';
  }
  if (userChoice === computerChoice){
    return 'the game was a tie';
  } 
  if (userChoice === 'rock'){
    if (computerChoice === 'paper'){
      return 'coomputer wins';
    } else {
      return 'user wins';
    }
  }
  if (userChoice = 'paper'){
    if (computerChoice = 'scissors'){
      return 'computer wins';
    } else {
      return 'user wins';
    }
  }
  if (userChoice === 'scissors'){
    if(computerChoice === 'rock'){
      return 'computer wins';
    }else {
      return 'user wins';
    }
  }
};


const playGame = () => {
   const userChoice = getUserChoice('bomb');
   const computerChoice = getComputerChoice();
  console.log(determineWinner(userChoice, computerChoice));
};

playGame();

4 thoughts on “#NoCode to #SomeCode”

Leave a Reply

Your email address will not be published. Required fields are marked *