Skip to content

Instantly share code, notes, and snippets.

@yongghongg
Last active March 9, 2021 07:04
Show Gist options
  • Save yongghongg/405c2d21ebc9d7dafaa862cfff1db1f2 to your computer and use it in GitHub Desktop.
Save yongghongg/405c2d21ebc9d7dafaa862cfff1db1f2 to your computer and use it in GitHub Desktop.
japanese_dict_app.gs
function getJapReading(word) {
var url = "http://jisho.org/api/v1/search/words?keyword=" + word;
var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
var json = JSON.parse(response.getContentText());
japReading = json.data[0].japanese[0].reading;
return japReading;
}
function getEnglishDef(word) {
var url = "http://jisho.org/api/v1/search/words?keyword=" + word;
var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
var json = JSON.parse(response.getContentText());
englishDef = json.data[0].senses[0].english_definitions;
return englishDef.join(", ");
}
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Custom Menu')
.addItem('Quiz', 'showQuiz')
.addToUi();
}
function showQuiz(){
var s = SpreadsheetApp.getActiveSheet();
var ALastRow = s.getRange("A1:A").getValues().filter(String).length;
var rand = Math.floor(Math.random() * (ALastRow-2) + 2);
var ques = s.getRange(rand, 1).getValue();
var correctAns = s.getRange(rand, 2).getValue();
var ui = SpreadsheetApp.getUi();
var input = ui.prompt(ques, ui.ButtonSet.OK_CANCEL);
var answer = input.getResponseText();
if (input.getSelectedButton() == ui.Button.OK) {
if (answer === correctAns) {
var cont = ui.alert("Correct! \n Do you want to continue?", ui.ButtonSet.YES_NO);
} else {
var cont = ui.alert(`Wrong! \n正解は【${correctAns}】\n Do you want to continue?`, ui.ButtonSet.YES_NO);}
if (cont === ui.Button.YES) {
showQuiz();
} else {
return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment