How to make Alexa read a simple dictionary?


I’m trying to make Alexa pick an item from a dictionary by his name

const Alexa = require('ask-sdk-core');

const garbage = [
    { 'name': 'can', 'color': 'green' },
    { 'name': 'magazine', 'color': 'red' },
    { 'name': 'bottle',  'color': 'yellow'},
    { 'name': 'crap', 'color': 'gray'},
    { 'name': 'apple', 'color': 'brown'}

and reply with a defined color

const RecycleIntentHandler = {
    handle(handlerInput) {
        const {requestEnvelope, responseBuilder} = handlerInput;
        const {intent} = requestEnvelope.request;
        const object = Alexa.getSlotValue(requestEnvelope, 'object');
        let res = garbage(el => === object);
        var speechText = (res.color);

        return handlerInput.responseBuilder

(store what the users said in "object", then search in the dictionary and pronounce his colour)

I tried different combination of code but I can’t make it work.
What am I doing wrong?


Use the find function:

let res = garbage.find(el => === object);

Your constant name gargabe is not a function. It’s a constant.

Answered By – callmemath

Answer Checked By – Willingham (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.