samedi 29 février 2020

My if else statement is not working as intended - innerHTML remaining the same for all statements

I am trying to find out why my conditional statement is not working as intended. The else part of the statement is not working at all, as it remains the same as for the else if statement. I tried to simplify the statement just having an if/else, but it didn't work. I will really appreciate some help to get to the bottom of this issue.

P.S. In my case if I want to use the null statement I must use it as a string. Another mystery.

Here's my code:

var name = prompt("Could you please tell me your name?");
    var newP = document.createElement('p');
    newP.setAttribute('id', 'mainP');
    document.body.appendChild(newP);


    if(name == 'null' || '') {
        newP.innerHTML = "I'm just looking for Aname! " + String.fromCodePoint(0x1F612);
    }else if(name == 'Aname' || 'aname') {
        newP.innerHTML = 'Yes, I finally found Aname! ' + String.fromCodePoint(0x1F60D);
    }else {
        newP.innerHTML = "I'm just looking for Aname! " + String.fromCodePoint(0x1F612);
    }

Aucun commentaire:

Enregistrer un commentaire