Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F88802824
quiz.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Oct 20, 18:32
Size
1 KB
Mime Type
text/x-c++
Expires
Tue, Oct 22, 18:32 (2 d)
Engine
blob
Format
Raw Data
Handle
21819371
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
quiz.js
View Options
'use strict';
const SelectPrompt = require('./select');
class Quiz extends SelectPrompt {
constructor(options) {
super(options);
if (typeof this.options.correctChoice !== 'number' || this.options.correctChoice < 0) {
throw new Error('Please specify the index of the correct answer from the list of choices');
}
}
async toChoices(value, parent) {
let choices = await super.toChoices(value, parent);
if (choices.length < 2) {
throw new Error('Please give at least two choices to the user');
}
if (this.options.correctChoice > choices.length) {
throw new Error('Please specify the index of the correct answer from the list of choices');
}
return choices;
}
check(state) {
return state.index === this.options.correctChoice;
}
async result(selected) {
return {
selectedAnswer: selected,
correctAnswer: this.options.choices[this.options.correctChoice].value,
correct: await this.check(this.state)
};
}
}
module.exports = Quiz;
Event Timeline
Log In to Comment