mercredi 21 août 2019

ReferenceError: variable is not defined.. again

I'm new at this so please be kind but I'm totally open to constructive criticism.

I need help making sure this function is running properly. when i try to console.log(var) i keep getting var is not defined.

This function should accept an array of dwarf names. It should then return a string with the numbered dwarves. The string should look like this: "1. Doc 2. Dopey 3. Bashful 4. Grumpy "

I've searched around but can't seem to find any answers.

function dwarfRollCall(dwarves) {
  var names = [ "Dopey", "Grumpy", "Bashful"]
  var dwarfNames = "";
    for(var i = 0; i < names.length; i++) {
        if(i === names.length+1) {
            dwarfNames += (i+1 + ". " + names [i]);
        }else {
            dwarfNames += (i+1 + ". " + names [i] + " ");
        }
    }
    return dwarfNames;
}

Aucun commentaire:

Enregistrer un commentaire