Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

370
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda