Skip to content

Instantly share code, notes, and snippets.

@TheDreamSaver
Last active May 29, 2021 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheDreamSaver/d4e6013300a65bd7f45db7aa39e3531c to your computer and use it in GitHub Desktop.
Save TheDreamSaver/d4e6013300a65bd7f45db7aa39e3531c to your computer and use it in GitHub Desktop.
Rock Paper Scissors Alexa Skill
const GamePlayIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'GamePlayIntent';
},
handle(handlerInput) {
const userAction = Alexa.getSlotValue(handlerInput.requestEnvelope, 'choice');
let speakOutput = '';
let repromptOutput =' What is your next move?';
const ACTIONS=[
'paper',
'rock',
'scissors'
];
const alexaAction=ACTIONS[Math.floor(Math.random()*ACTIONS.length)];
const result = userAction+alexaAction;
switch(result)
{
case 'rockrock':
speakOutput+="you played rock and i played rock, it is a tie! ";
break;
case 'rockpaper':
speakOutput+="you played rock and i played paper, I win! ";
break;
case 'rockscissors':
speakOutput+="you played rock and i played scissors, you win! congratulations ";
break;
case 'paperrock':
speakOutput+="you played paper and i played rock, you win! congratulations ";
break;
case 'paperpaper':
speakOutput+="you played paper and i played paper, it is a tie! ";
break;
case 'paperscissors':
speakOutput+="you played paper and i played scissors, I win! ";
break;
case 'scissorsrock':
speakOutput+="you played scissors and i played rock, I win! ";
break;
case 'scissorspaper':
speakOutput+="you played scissors and i played paper, you win! congratulations ";
break;
case 'scissorscissors':
speakOutput+="you played scissors and i played scissors, it is a tie! ";
break;
default:
break;
}
return handlerInput.responseBuilder
.speak(speakOutput + repromptOutput)
.reprompt(repromptOutput)
.getResponse();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment