JSFiddle - React, Tailwind, and code Playground

JavaScript Challenge: --------------------------- Prompt user for name. Add name to array If name is empty, console.log the names in alphabetical order. Press F12 to open console to see the results

by chrisallenmoore

HTML

<!--
JavaScript Challenge:
Prompt user for name
Add name to array If name is empty, console.log the names in alphabetical order
Press F12 to open console to see the results
-->

JavaScript

var names = [];
var keepGoing = true;

var getNames = function () {
    while (keepGoing) {
        var name = prompt("add a name");

        if ((name === "") | (name === null)) {
            keepGoing = false;
            printNamesOut();
        } else {
            names.push(name);
        }
    }
};



var printNamesOut = function () {
    names.sort();
    for (var i = 0; i < names.length; i++) {
        console.log(names[i]);
    }
};

getNames();