JSFiddle - React, Tailwind, and code Playground

by nabeezy

JavaScript

base = ['one','two','three','four','five','six','seven','eight','nine'];
teens = ['ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen'];
decs = ['twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety'];
ten = 'ten';
hundred ='hundred';
and = 'and';
thousand = 'thousand';
onethousand = 'onethousand';

var total = 0;
// 1 - 9  --------------------------------------------------------
for(var a = 0; a < base.length; a++){
    total+= base[a].length;
}
// 10 - 19  --------------------------------------------------------
for(var b = 0; b < teens.length; b++){
    total+= teens[b].length;
}
// 21 - 99 --------------------------------------------------------
for(var c = 0; c < decs.length; c++){
    total += decs[c].length;// 20,30,40,50, etc...
    for(var d = 0; d < base.length; d++){
        var word = decs[c]+base[d];
        total += word.length;
    }
}
// 100 - 999
for(var e = 0; e < base.length; e++){
    var word = base[e] + hundred; // 100, 200, 300, etc...
    total += word.length;
    for(var h = 0; h < base.length; h++){ //101 - 109, 201 - 209, 301 - 309, etc...
        var word = base[e]+hundred+and+base[h];
        total += word.length;
    }
    for(var i = 0; i < teens.length; i++){
        var word = base[e]+hundred+and+teens[i]; //110 - 119, 210 - 219, etc...
        total += word.length;
    }
    for(var f = 0; f < decs.length; f++){
        var word = base[e] + hundred + and + decs[f]; // 120,130,140,150...
        total += word.length;
        for(var g = 0; g < base.length; g++){
            var word = base[e]+hundred+and+decs[f]+base[g];
            total += word.length;
        }
    }
    
}
total += onethousand.length;
alert(total);

// handle 110 210,310 etc....
// handle 120, 130, 140, ... 220, 230, 240...