vendredi 6 octobre 2017

Print out random text from an array when the program is run (Javascript) [duplicate]

This question already has an answer here:

I am making a random greeting generator in javascript and just want a new random greeting to print out every time i run the program in node.js. I have my code here but it wont seem to work. It still only prints out the array number and not the text greetings.

Anyone got a tip on what i can do?

var greetings = [
      "hello"
    , "ciao"
    , "welcome"
    , "howdy"
    , "greetings"
    , "salut"
    , "hallo"
    , "hola"
    , "Gday"
    , "Hey"
];
var greeting = Math.floor(Math.random() * greetings.length);

greetings[greeting];

greeting.toString();

console.log(greeting);




Aucun commentaire:

Enregistrer un commentaire