StudyBuddy is a virtual study partner that you can give you oral quizzes on the go. With StudyBuddy, you can upload your own flash cards or get quizzed with flash cards from your classmates or public flash cards from students around the world. Now you can have interactive study sessions in the car, shower, and even while you work out. StudyBuddy is even accessible to the blind or visually impaired. Retain more information using spaced repetition in a more engaging format (compared to traditional text methods).

---------------------------------------------------- Proof-of-Concept Source Code--------------------------------------------------

'use strict';

var questions = [ { "What is A Cell?": [ "a basic unit of life" ] }, { "What is a nucleus?": [ "central part of the cell"

    ]
},
{
    "What is Botany?": [
        "study of plants" 
    ]
},
{
    "define zoology?": [
        "study of animals"
    ]
},
{
    "define micro biology?": [
        "study of micro organisms"
    ]
},

];

exports.handler = function (event, context) { try { console.log("event.session.application.applicationId=" + event.session.application.applicationId);

    if (event.session.new) {
        onSessionStarted({requestId: event.request.requestId}, event.session);
    }

    if (event.request.type === "LaunchRequest") {
        onLaunch(event.request,
            event.session,
            function callback(sessionAttributes, speechletResponse) {
                context.succeed(buildResponse(sessionAttributes, speechletResponse));
            });
    } else if (event.request.type === "IntentRequest") {
        onIntent(event.request,
            event.session,
            function callback(sessionAttributes, speechletResponse) {
                context.succeed(buildResponse(sessionAttributes, speechletResponse));
            });
    } else if (event.request.type === "SessionEndedRequest") {
        onSessionEnded(event.request, event.session);
        context.succeed();
    }
} catch (e) {
    context.fail("Exception: " + e);
}

};

function onSessionStarted(sessionStartedRequest, session) { console.log("onSessionStarted requestId=" + sessionStartedRequest.requestId + ", sessionId=" + session.sessionId);

}

function onLaunch(launchRequest, session, callback) { console.log("onLaunch requestId=" + launchRequest.requestId + ", sessionId=" + session.sessionId);

getWelcomeResponse(callback);

}

function onIntent(intentRequest, session, callback) { console.log("onIntent requestId=" + intentRequest.requestId + ", sessionId=" + session.sessionId);

var intent = intentRequest.intent,
    intentName = intentRequest.intent.name;

if (session.attributes && session.attributes.userPromptedToContinue) {
    delete session.attributes.userPromptedToContinue;
    if ("AMAZON.NoIntent" === intentName) {
        handleFinishSessionRequest(intent, session, callback);
    } else if ("AMAZON.YesIntent" === intentName) {
        handleRepeatRequest(intent, session, callback);
    }
}

    if ("AnswerIntent" === intentName) {
    handleAnswerRequest(intent, session, callback);
} else if ("AnswerOnlyIntent" === intentName) {
    handleAnswerRequest(intent, session, callback);
} else if ("DontKnowIntent" === intentName) {
    handleAnswerRequest(intent, session, callback);
} else if ("AMAZON.YesIntent" === intentName) {
    handleAnswerRequest(intent, session, callback);
} else if ("AMAZON.NoIntent" === intentName) {
    handleAnswerRequest(intent, session, callback);
} else if ("AMAZON.StartOverIntent" === intentName) {
    getWelcomeResponse(callback);
} else if ("AMAZON.RepeatIntent" === intentName) {
    handleRepeatRequest(intent, session, callback);
} else if ("AMAZON.HelpIntent" === intentName) {
        handleGetHelpRequest(intent, session, callback);
} else if ("AMAZON.StopIntent" === intentName) {
    handleFinishSessionRequest(intent, session, callback);
} else if ("AMAZON.CancelIntent" === intentName) {
    handleFinishSessionRequest(intent, session, callback);
} 

}

function onSessionEnded(sessionEndedRequest, session) { console.log("onSessionEnded requestId=" + sessionEndedRequest.requestId + ", sessionId=" + session.sessionId);

}

var ANSWER_COUNT = 1; var GAME_LENGTH = 3;

var CARD_TITLE = "Study buddy";

function getWelcomeResponse(callback) {

var sessionAttributes = {},

    speechOutput = "I will ask you " + GAME_LENGTH.toString()
        + " questions, try to get as many right as you can. Just say the answer. Let's begin. ",
    shouldEndSession = false,

    gameQuestions = populateGameQuestions(),
    correctAnswerIndex = Math.floor(Math.random() * (ANSWER_COUNT)), // Generate a random index for the correct answer, from 0 to 3
    roundAnswers = populateRoundAnswers(gameQuestions, 0, correctAnswerIndex),

    currentQuestionIndex = 0,
    spokenQuestion = Object.keys(questions[gameQuestions[currentQuestionIndex]]),
    repromptText = spokenQuestion,

    i, j;

for (i = 0; i < ANSWER_COUNT; i++) {
    repromptText += ""
}
speechOutput += repromptText;
sessionAttributes = {
    "speechOutput": repromptText,
    "repromptText": repromptText,
    "currentQuestionIndex": currentQuestionIndex,
    "correctAnswerIndex": correctAnswerIndex + 1,
    "questions": gameQuestions,
    "score": 0,
    "correctAnswerText":
        questions[gameQuestions[currentQuestionIndex]][Object.keys(questions[gameQuestions[currentQuestionIndex]])[0]][0]
};
callback(sessionAttributes,
    buildSpeechletResponse(CARD_TITLE, speechOutput, repromptText, shouldEndSession));

}

function populateGameQuestions() { var gameQuestions = []; var indexList = []; var index = questions.length;

if (GAME_LENGTH > index){
    throw "Invalid Game Length.";
}

for (var i = 0; i < questions.length; i++){
    indexList.push(i);
}


for (var j = 0; j < GAME_LENGTH; j++){
    var rand = Math.floor(Math.random() * index);
    index -= 1;

    var temp = indexList[index];
    indexList[index] = indexList[rand];
    indexList[rand] = temp;
    gameQuestions.push(indexList[index]);
}

return gameQuestions;

}

function populateRoundAnswers(gameQuestionIndexes, correctAnswerIndex, correctAnswerTargetLocation) {

var answers = [],
    answersCopy = questions[gameQuestionIndexes[correctAnswerIndex]][Object.keys(questions[gameQuestionIndexes[correctAnswerIndex]])[0]],
    temp, i;

var index = answersCopy.length;

if (index < ANSWER_COUNT){
    throw "Not enough answers for question.";
}


for (var j = 1; j < answersCopy.length; j++){
    var rand = Math.floor(Math.random() * (index - 1)) + 1;
    index -= 1;

    var temp = answersCopy[index];
    answersCopy[index] = answersCopy[rand];
    answersCopy[rand] = temp;
}


for (i = 0; i < ANSWER_COUNT; i++) {
    answers[i] = answersCopy[i];
}
temp = answers[0];
answers[0] = answers[correctAnswerTargetLocation];
answers[correctAnswerTargetLocation] = temp;
return answers;

}

function handleAnswerRequest(intent, session, callback) { var speechOutput = ""; var sessionAttributes = {}; var gameInProgress = session.attributes && session.attributes.questions; var answerSlotValid = isAnswerSlotValid(intent); var userGaveUp = intent.name === "DontKnowIntent";

if (!gameInProgress) {

    sessionAttributes.userPromptedToContinue = true;
    speechOutput = "Your answer is invalid. You want to start the quiz again? ";
    callback(sessionAttributes,
        buildSpeechletResponse(CARD_TITLE, speechOutput, speechOutput, false));
} else if (!answerSlotValid && !userGaveUp) {

    var reprompt = session.attributes.speechOutput;
    var speechOutput = "Sorry, your answer is not is our list. " + reprompt;
    callback(session.attributes,
        buildSpeechletResponse(CARD_TITLE, speechOutput, reprompt, false));
} else {
    var gameQuestions = session.attributes.questions,
        correctAnswerIndex = parseInt(session.attributes.correctAnswerIndex),
        currentScore = parseInt(session.attributes.score),
        currentQuestionIndex = parseInt(session.attributes.currentQuestionIndex),
        correctAnswerText = session.attributes.correctAnswerText;

    var speechOutputAnalysis = "";

    if (answerSlotValid && intent.slots.Answer.value.toUpperCase() == correctAnswerText.toUpperCase()) {
        currentScore++;
        speechOutputAnalysis = "correct. ";
    } else {
        if (!userGaveUp) {
            speechOutputAnalysis = "wrong. "
        }
        speechOutputAnalysis += "The correct answer is " + correctAnswerText + ". ";
    }

    if (currentQuestionIndex == GAME_LENGTH - 1) {
        speechOutput = userGaveUp ? "" : "That answer is ";
        speechOutput += speechOutputAnalysis + "You got " + currentScore.toString() + " out of "
            + GAME_LENGTH.toString() + " questions correct. Thank you for learning with study buddy!";
        callback(session.attributes,
            buildSpeechletResponse(CARD_TITLE, speechOutput, "", true));
    } else {
        currentQuestionIndex += 1;
        var spokenQuestion = Object.keys(questions[gameQuestions[currentQuestionIndex]]);

        correctAnswerIndex = Math.floor(Math.random() * (ANSWER_COUNT));
        var roundAnswers = populateRoundAnswers(gameQuestions, currentQuestionIndex, correctAnswerIndex),

            questionIndexForSpeech = currentQuestionIndex + 1,
            repromptText =  spokenQuestion ;
        for (var i = 0; i < ANSWER_COUNT; i++) {
            repromptText +=  ""
        }
        speechOutput += userGaveUp ? "" : "That answer is ";
        speechOutput += speechOutputAnalysis + "Your score is " + currentScore.toString() + ". " + repromptText;

        sessionAttributes = {
            "speechOutput": repromptText,
            "repromptText": repromptText,
            "currentQuestionIndex": currentQuestionIndex,
            "correctAnswerIndex": correctAnswerIndex + 1,
            "questions": gameQuestions,
            "score": currentScore,
            "correctAnswerText":
                questions[gameQuestions[currentQuestionIndex]][Object.keys(questions[gameQuestions[currentQuestionIndex]])[0]][0]
        };
        callback(sessionAttributes,
            buildSpeechletResponse(CARD_TITLE, speechOutput, repromptText, false));
    }
}

}

function handleRepeatRequest(intent, session, callback) {

if (!session.attributes || !session.attributes.speechOutput) {
    getWelcomeResponse(callback);
} else {
    callback(session.attributes,
        buildSpeechletResponseWithoutCard(session.attributes.speechOutput, session.attributes.repromptText, false));
}

}

function handleGetHelpRequest(intent, session, callback) {

if (session.attributes) {
    session.attributes.userPromptedToContinue = true;
} else {

    session.attributes = { userPromptedToContinue: true };
}


var speechOutput = "To start a new quiz at any time, say, open biology quiz. "
    + "To repeat the last element, say, repeat. "
    + "Would you like to keep studying?",
    repromptText = "Try to get the right answer. "
    + "Would you like to keep studying?";
    var shouldEndSession = false;
callback(session.attributes,
    buildSpeechletResponseWithoutCard(speechOutput, repromptText, shouldEndSession));

}

function handleFinishSessionRequest(intent, session, callback) {

callback(session.attributes,
    buildSpeechletResponseWithoutCard("Thank you for learning with Study Buddy!", "", true));

}

function isAnswerSlotValid(intent) { var answerSlotFilled = intent.slots && intent.slots.Answer && intent.slots.Answer.value; var answerSlotIsInt = answerSlotFilled && !isNaN(parseInt(intent.slots.Answer.value)); return 1; }

function buildSpeechletResponse(title, output, repromptText, shouldEndSession) { return { outputSpeech: { type: "PlainText", text: output }, card: { type: "Simple", title: title, content: output }, reprompt: { outputSpeech: { type: "PlainText", text: repromptText } }, shouldEndSession: shouldEndSession }; }

function buildSpeechletResponseWithoutCard(output, repromptText, shouldEndSession) { return { outputSpeech: { type: "PlainText", text: output }, reprompt: { outputSpeech: { type: "PlainText", text: repromptText } }, shouldEndSession: shouldEndSession }; }

function buildResponse(sessionAttributes, speechletResponse) { return { version: "1.0", sessionAttributes: sessionAttributes, response: speechletResponse }; }

Built With

Share this project:

Updates

posted an update

You know what, why use textbooks, when you can use STUDY BUDDY. Study Buddy is a virtual app that you can use to facilitate you with homework, practice quizzes, math problems, and more. Whats great about study buddy is its virtual reality. With this interface studying is not only more viewable to users but also more interactive as well. Use it for "searches with Alexa" or quizzing your friends. Study Buddy is an app you simply can't live without. So be sure to download and remember, everyone needs a Study Buddy

Log in or sign up for Devpost to join the conversation.