mardi 13 septembre 2016

Save multiple values in one variable

Anyway, I'm trying to make a program that take your birthdate (yymmd), replaces the numbers with strings and output your "real birthname".

Problem is that the loop only output the string for the last number typed into the prompt and += with itself. I was kind of hoping it would iterate through the loop and add one string after another in the birthname variable.

(This is my first own code so be gentle) :)

var birthDate = prompt("write your birthdate!");
birthDateSplitter = birthDate.split("");
len = birthDateSplitter.length,
birthName = 0;
var i = 0;

for (i; i < len; i++) {
    if (birthDateSplitter[i] == 9) {
        birthName = "do";
    } else if (birthDateSplitter[i] == 8) {
        birthName = "ka";
    } else if (birthDateSplitter[i] == 7) {
        birthName = "mu";
    } else if (birthDateSplitter[i] == 6) {
        birthName = "ssa";
    } else if (birthDateSplitter[i] == 5) {
        birthName = "tto";
    } else if (birthDateSplitter[i] == 4) {
        birthName = "ti";
    } else if (birthDateSplitter[i] == 3) {
        birthName = "le";
    } else if (birthDateSplitter[i] == 2) {
        birthName = "pa";
    } else if (birthDateSplitter[i] == 1) {
        birthName = "bu";
    } else {
        birthName = "vi";
    } 
    birthName += birthName;
}

alert("Your real birthname is " + birthName);

Aucun commentaire:

Enregistrer un commentaire