Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

369
Views
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 => el.name === object);
        var speechText = (res.color);

        return handlerInput.responseBuilder
            .speak(speechText)
    }
};

(store what the users said in "object", then search object.name 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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use the find function:

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

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!