mardi 10 février 2015

my if-statement giving wrong answer

This is an assignment that is suppose to print safe or busted depending on if total3 is more or less than total4.



var c4 =5;
var c5 =1;
var c6 =4;
var d4 =1;
var d5 =11;
var d6 =1;

var total3 = c4+c5+c6;
var total4 = d4+d5+d6;

var printResult = function(player,dealer){
var game1 = "Player: "+total3 +", Dealer: "+total4;
return game1;
}
if (total3 > total4){
total3 = 'safe';
total4 = 'busted';
}
if (total4 > total3) {
total4 = 'safe';
total3 = 'busted';
}


ANSWER = printResult(total3,total4);


The answer I'm getting is: "Player: busted, Dealer: safe"


But the answer I'm suppose to get is: "Player: safe, Dealer: safe"


Any help to understand why it's not working as intended is appreciated!


Aucun commentaire:

Enregistrer un commentaire