helloworld
helloworld

Reputation: 15

Can alert show two parameters at the same time?

function bj(numa,numb){
    if(numa>numb){
        alert(numa);
    }
    else if(numa==numb){
        alert(numa,numb);
    }
    else{
        alert(numb);
    }
}

I mean, in the above function when the two numbers are equal, the pop-up window appears two values. Can I do that?

Upvotes: 1

Views: 44

Answers (3)

Koby Douek
Koby Douek

Reputation: 16673

You can concatenate them:

alert('number1: ' + numa + ' number2: ' + numb);

Upvotes: 1

epascarello
epascarello

Reputation: 207517

You need to concatenate them

alert(numa + "," + numb);
alert(numa + "\n" + numb);

Upvotes: 1

Deanmv
Deanmv

Reputation: 1211

Depending on what you want to display you can do something like the below

function bj(numa,numb){
    if(numa>numb){
        alert(numa);
    }
    else if(numa==numb){
        alert(numa + " = " + numb);
    }
    else{
        alert(numb);
    }
}

This would display the below if numa and numb were 12

12 = 12

Upvotes: 1

Related Questions