Skip to content

Instantly share code, notes, and snippets.

@nimitmaru
Created March 1, 2014 22:13
Show Gist options
  • Save nimitmaru/9298277 to your computer and use it in GitHub Desktop.
Save nimitmaru/9298277 to your computer and use it in GitHub Desktop.
// TextOlympics - Driver File
// Road to Code - Fullstack Academy
//
// This is the file you have to edit
var my_channel = "nimits_channel"; //select your channel name. must be one word (no spaces).
var all_phone_numbers = "";
var sendQuestion = function () {
var question_text = $('#question_text').val();
all_phone_numbers = $('#phone_numbers_input').val();
addLog("Trying to send question to friends...");
sendMessageToSMSExchange(question_text, all_phone_numbers);
};
var verifyResponse = function(responseObj) {
var answer_expected = $('#answer_expected_input').val();
var friends_answer = responseObj.response;
var friends_cell_num = responseObj.number;
addLog("Friend response received and starting to verifyResponse.")
if (friends_answer === answer_expected) {
// correct answer is found
sendSMS("Correct! you are so cool.", friends_cell_num);
reportGameOverToAll(friends_cell_num, answer_expected);
} else {
// wrong answer
sendSMS("Sorry, wrong answer. Try again!", friends_cell_num);
}
};
var reportGameOverToAll = function (winners_number, correct_answer) {
addLog("Reporting Game Over")
pusher.unsubscribe(my_channel);
var all_numbers = $('#phone_numbers_input').val();
var all_numbers_array = all_numbers.split(',');
var i = 0;
while (i < all_numbers_array.length) {
if (current_number != winners_number) {
current_number = all_numbers_array[i];
var sms_text = "Winner was found. correct answer is: " + correct_answer + ". The winner was: " + winners_number;
sendSMS(sms_text, current_number);
}
}
// START YOUR CODE HERE
// we should report to all friends the game is over by sending an SMS to them.
// you may want to tell them also who won!
};
$('#send_question_button').click(function() {
sendQuestion();
$(this).prop("disabled", true);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment