/    Sign up×
Community /Pin to ProfileBookmark

Alert message not what I expected

Hello,

I am trying to learn JavaScript and I have set up the code below. In my Alert dialog when I run it, I get the value 600. I am trying to get it to say the sentence..

“high score belongs to (either playerOne or playerTwo)….instead the alert says 600.
can someone tell me what I am doing wrong??
thanks
babs

var playerOne=500;
var playerTwo=600;

var highScore;

if (playerOne>playerTwo){
highScore=playerOne;
}
else {
highScore=playerTwo;
}

alert (“high score belongs to ” && highScore);

thanks!

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@TheAliveWinnerFeb 26.2012 — [code=html]
<script>
var playerOne=500;
var playerTwo=600;

if (playerOne>playerTwo){
alert("high score belongs to playerOne!");
}
else {
alert("high score belongs to playerTwo!");
}
</script>
[/code]
Copy linkTweet thisAlerts:
@TheAliveWinnerFeb 26.2012 — [code=html]var playerOne=500;
var playerTwo=600;

var highScore;

if (playerOne>playerTwo){
highScore="playerOne";
}
else {
highScore="playerTwo";
}
alert ("high score belongs to " + highScore);[/code]


Use [COLOR="Red"][B]+ [/B][/COLOR]instead of [B][COLOR="Red"]&&[/COLOR][/B]
Copy linkTweet thisAlerts:
@TheAliveWinnerFeb 26.2012 — [B]Note: When you assign a text value to a variable, use quotes around the value.[/B]

Use:
[CODE]highScore="playerOne";[/CODE]
Instead of:
[CODE]highScore=playerOne;[/CODE]
Check: http://www.w3schools.com/js/js_variables.asp
Copy linkTweet thisAlerts:
@TheAliveWinnerFeb 26.2012 — [I]The [COLOR="Red"]+ [/COLOR]operator is used to add string variables or text values together.



To add two or more string variables together, use the [COLOR="Red"]+ [/COLOR]operator.



[COLOR="Red"]&&[/COLOR] is not used to do that![/I]


[I]Check[/I]:[COLOR="DarkSlateGray"] http://www.w3schools.com/js/js_operators.asp[/COLOR]
Copy linkTweet thisAlerts:
@ibabsauthorFeb 26.2012 — Hello!

Thank you so much for all of this....

very helpful...

I will also check out the W3C site you have recommended!

thanks

babs ?
Copy linkTweet thisAlerts:
@ibabsauthorFeb 26.2012 — Hello!

Thank you so much for all of this....

very helpful...

I will also check out the W3schools site you have recommended!

thanks

babs ?
Copy linkTweet thisAlerts:
@TheAliveWinnerFeb 26.2012 — Hello!

Thank you so much for all of this....

very helpful...

I will also check out the W3C site you have recommended!

thanks

babs ?[/QUOTE]


[B][I][COLOR="Red"]You are welcome, dear![/COLOR][/I][/B]

:p
×

Success!

Help @ibabs spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...