Chetan Bhanushali
Created June 14, 2017

Programming Facts

Various facts about the programming and computers that make up a large part of our everyday lives.

26
Programming Facts

Things used in this project

Story

Read more

Code

Programming Skill Code

JavaScript
paste into inline editor in AWS Lambda Function
'use strict';

const Alexa = require('alexa-sdk');

const APP_ID = undefined;  // TODO replace with your app ID (OPTIONAL).

const languageStrings = {
    'en': {
        translation: {
            FACTS: [
                'The first computer programmer was a female, named Ada Lovelace.',
                'The first computer was actually a loom called the Jacquard loom, an automated, mechanical loom, which didn’t use any electricity.',
                'The first high-level (very close to real English that we use to communicate) programming language was FORTRAN. invented in 1954 by IBM’s John Backus.',
                'Computer programming is one of the fastest growing occupations currently',
                'The first computer “bug” was named after a real bug, when a moth was discovered stuck in a relay',
                'The computer virus was initially designed without any harmful intentions',
                'If computer programming were a country, it would be the third most diverse for languages spoken',
                'Most web pages are built using more than one programming language. An e-mail website, for example, is made with three programming languages: CSS, HTML, and JavaScript.',
                'Coders who study and write malware are known as hackers. Those who write malware to commit crimes are known as “black-hat” hackers, and those who write programs to protect against malware are called “white-hat" hackers.',
                'Spacecraft often run using old-fashioned computer systems because engineers are confident their programs do the job well, while making a new one is risky and expensive. NASA’s reusable spacecraft, the Space Shuttle, went into space using a computer designed in the 1970s. It had less code than most of today’s cell phones!',
                'Used in World War 2, the colossus machines were the first programmable electronic digital computers.',
                'Shakespeare is a programming language based on the writings of the great playwright. Each program contains a title, acts, scenes and characters to make brilliant source code that is actually fun to read.',
                'Programs called quines exist that can create replicas of themselves, not by copying, but by assembling.',
            ],
            SKILL_NAME: 'Programming Facts',
            GET_FACT_MESSAGE: "Here's your fact: ",
            HELP_MESSAGE: 'You can say tell me a programming fact, or, you can say exit... What can I help you with?',
            HELP_REPROMPT: 'What can I help you with?',
            STOP_MESSAGE: 'Goodbye!',
        }
    }
};

const handlers = {
    'LaunchRequest': function () {
        this.emit('GetFact');
    },
    'GetNewFactIntent': function () {
        this.emit('GetFact');
    },
    'GetFact': function () {
        // Get a random programming fact from the programmming facts list
        // Use this.t() to get corresponding language data
        const factArr = this.t('FACTS');
        const factIndex = Math.floor(Math.random() * factArr.length);
        const randomFact = factArr[factIndex];

        // Create speech output
        const speechOutput = this.t('GET_FACT_MESSAGE') + randomFact;
        this.emit(':tellWithCard', speechOutput, this.t('SKILL_NAME'), randomFact);
    },
    'AMAZON.HelpIntent': function () {
        const speechOutput = this.t('HELP_MESSAGE');
        const reprompt = this.t('HELP_MESSAGE');
        this.emit(':ask', speechOutput, reprompt);
    },
    'AMAZON.CancelIntent': function () {
        this.emit(':tell', this.t('STOP_MESSAGE'));
    },
    'AMAZON.StopIntent': function () {
        this.emit(':tell', this.t('STOP_MESSAGE'));
    },
};

exports.handler = function (event, context) {
    const alexa = Alexa.handler(event, context);
    alexa.APP_ID = APP_ID;
    // To enable string internationalization (i18n) features, set a resources object.
    alexa.resources = languageStrings;
    alexa.registerHandlers(handlers);
    alexa.execute();
};

Credits

Chetan Bhanushali

Chetan Bhanushali

0 projects • 0 followers

Comments