var https = require('https')

exports.handler = (event, context) => {

  try {

    if (event.session.new) {
      // New Session
      console.log("NEW SESSION")
    }

    switch (event.request.type) {

      case "LaunchRequest":
        // Launch Request
        console.log(`LAUNCH REQUEST`)
        context.succeed(
          generateResponse(
            buildSpeechletResponse("Starting Ping Pong", false),
            {team1: 0, team2: 0}
          )
          // Intialize the score
          resetScore(event);
          // event.session.attributes.team1 // Access sample
          // event.session.attributes.team2 // Access sample
          // Read Score
          readScore(event);
        )
        break;

      case "IntentRequest":
        // Intent Request
        console.log(`INTENT REQUEST`)

        switch(event.request.intent.name) {
          case "AddPoint":
            break;

          case "SubtractPoint":
            break;

          case "ResetGame":
            break;

          case "ReadScore":
            break;

          case "EndGame":
            // End the session here
            break;

          default:
            throw "Invalid intent"
        }

        break;

      case "SessionEndedRequest":
        // Session Ended Request
        console.log(`SESSION ENDED REQUEST`)
        break;

      default:
        context.fail(`INVALID REQUEST TYPE: ${event.request.type}`)

    }

  } catch(error) { context.fail(`Exception: ${error}`) }

}

// Helpers
buildSpeechletResponse = (outputText, shouldEndSession, reprompt) => {

  return {
    outputSpeech: {
      type: "PlainText",
      text: outputText
    },
    shouldEndSession: shouldEndSession,
    reprompt: {
      outputSpeech: {
        type: "PlainText",
        text: reprompt || ''
      }
    }
  }

}

generateResponse = (speechletResponse, sessionAttributes) => {

  return {
    version: "1.0",
    sessionAttributes: sessionAttributes,
    response: speechletResponse
  }

}

readScore = () => {
          generateResponse(
            buildSpeechletResponse("Player 1 Score is "+event.session.attributes.team1, false),
            {team1: 0, team2: 0}
          )
}

resetScore = (event) => {
  event.session.attributes.team1 = 0;
  event.session.attributes.team2 = 0;
}
@@ -1023,24 +1023,54 @@
 ReadScore%22:%0A
+            readScore(event);%0A
             
@@ -2035,16 +2035,21 @@
 core = (
+event
 ) =%3E %7B%0A 
@@ -2055,172 +2055,156 @@
     
-      generateResponse(%0A            buildSpeechletResponse(%22Player 1 Score is %22+event.session.attributes.team1, false),%0A            %7Bteam1: 0, team2: 0%7D%0A          )
+var responseString = %22Team 1 Score is %22+event.session.attributes.team1+%22 Team 2 Score is %22+event.session.attributes.team2;%0A    return responseString
 %0A%7D%0A%0A

update to readScore()