I hope someone can help me. I try to create a multilingual Alexa skill.
There are language constants in my main file like provided from the sample code from Alexa like this:
const languageString = {
'en': {
'translation': {
'QUESTIONS': questions['QUESTIONS_EN_US'],
'GAME_NAME': 'My Quiz', // Be sure to change this for your skill.
'HELP_MESSAGE': 'I will ask you %s multiple choice questions. Respond with the number of the answer. ' +
'For example, say one, two, three, or four. To start a new game at any time, say, start game. ',
Everything is working fine and so I wanted to add now some alternate strings, so that the game is less boring. So I created a correct.js file and defined it in my document like this:
const correct = require('./correct');
This file looks like this:
'use strict';
module.exports = {
CORRECT_EN_GB: [
"Booya", "All righty", "Bam", "Bazinga", "Bingo", "Boom", "Bravo", "Cha Ching", "Cheers", "Dynomite",
"Hip hip hooray", "Hurrah", "Hurray", "Huzzah", "Oh dear. Just kidding. Hurray", "Kaboom", "Kaching", "Oh snap", "Phew",
"Righto", "Way to go", "Well done", "Whee", "Woo hoo", "Yay", "Wowza", "Yowsa"
],
CORRECT_EN_US: [
"Booya", "All righty", "Bam", "Bazinga", "Bingo", "Boom", "Bravo", "Cha Ching", "Cheers", "Dynomite",
"Hip hip hooray", "Hurrah", "Hurray", "Huzzah", "Oh dear. Just kidding. Hurray", "Kaboom", "Kaching", "Oh snap", "Phew",
"Righto", "Way to go", "Well done", "Whee", "Woo hoo", "Yay", "Wowza", "Yowsa"
],
CORRECT_DE_DE: [
"Aber hallo", "Bazinga", "Bingo", "Bravo", "Donnerwetter",
"en garde", "hipp hipp hurra", "hurra", "japp", "jawohl", "jo", "juhu", "na sieh mal einer an", "Stimmt",
"Super", "Supi", "tada", "türlich", "yay"
],
};
Now i want to retrieve a random value of the list inside my language strings and tried this code:
'ANSWER_CORRECT_MESSAGE': '<say-as interpret-as="interjection">' + correct['CORRECT_EN_US'][Math.floor(Math.random() * correct['CORRECT_EN_US'].length)] + '</say-as><break time="1s"/> your reply is correct.<break time="2s"/>',
But that does not work, to be honest I don't know how to retrieve a random value out of the (multidimensional?) array.
Can anyone lead me to the right code? Thank you!
Elisa