Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save benpearson/e876c92187064e0cf132e5a29393be18 to your computer and use it in GitHub Desktop.
Save benpearson/e876c92187064e0cf132e5a29393be18 to your computer and use it in GitHub Desktop.
Javascript question
// Howler
var words = new Howl({
src: ['sounds/words.mp3'],
sprite: {
all: [0, 693],
are: [693, 529],
as: [1228, 644],
at: [1871, 528],
but: [2421, 499],
for: [2924, 655],
had: [3578, 466],
have: [4065, 534],
he: [4600, 546],
her: [5148, 649],
his: [5801, 570],
not: [6382, 575],
on: [6959, 498],
one: [7460, 478],
said: [8044, 701],
so: [8891, 512],
they: [9408, 623],
we: [10051, 533],
with: [10601, 660],
you: [11364, 565]
}
});
var instructions = new Howl({
src: ['sounds/instructions.mp3'],
sprite: {
niceTry: [0, 1096],
findTheWord: [1096, 2000]
}
});
// Vue
var app = new Vue({
el: '#root',
data: {
wordsList: [ 'all', 'are', 'as', 'at', 'but', 'for', 'had', 'have', 'he', 'her', 'his', 'not', 'on', 'one', 'said', 'so', 'they', 'we', 'with', 'you' ],
quizWord: ''
},
methods: {
quizButtonClicked: function (event) {
// If no quiz word yet
if (!this.quizWord) {
// Set quiz word
this.setQuizWord();
}
this.speakQuizWord();
},
setQuizWord: function() {
this.quizWord = this.wordsList[ Math.floor( Math.random() * this.wordsList.length) ];
},
speakQuizWord: function() {
instructions.play('findTheWord');
// QUESTION: Is there a better way to do the following?
let quizWord = this.quizWord;
// Fires when the sound finishes playing.
instructions.once('end', function(){
words.play(quizWord);
}.bind(quizWord));
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment