/    Sign up×
Community /Pin to ProfileBookmark

Else If Statements

A coworker and I are worker on a game regarding poverty, we need help with else if statements as nothing is working, this is what we have.
<!DOCTYPE html>
<html>
<body>
<p>Click to play please!</p>
<button onclick=”FunctionGameIntro()”>Play</button>
<p id=”demo”></p>
<script>
function FunctionGameIntro() {
window.alert(“Welcome to the game.”);
var player1 = prompt(“Please enter your name.”, “”);
if (player1 != null) {
document.getElementById(“demo”).innerHTML =
“Hello ” + player1 + “! How are you today?”;
var money = 1500;
var money2 = 1300;
window.alert(“Your current balance is”);
window.alert(money);
window.alert(“Hello, today you will learn what it is like to be a person living with minimum wage!”)
var job=window.prompt(“Please enter Bellhop, McDonalds Cook, or Janitor.”);
window.alert(“Your current job is ” + job);
window.alert(“You need to buy a uniform, your balance is now “);
window.alert(money – 200);
window.alert(“You need to choose a healthcare plan.”);
var HealthCare=window.prompt(“Choose Bronze, Silver, Gold, or Platinum”);
if (HealthCare=”Bronze”)
{
window.alert(“You have chosen the bronze plan.”);
window.alert(“Your current balance is “);
window.alert(money2 – 100);
}
else if (HealthCare=”Silver”)
{
window.alert(“You have chosen the silver plan.”);
window.alert(“Your current balance is “);
window.alert(money2 – 200);
}
else if (HealthCare=”Gold”)
{
window.alert(“You have chosen the golden plan.”);
window.alert(“Your current balance is “);
window.alert(money2 – 300);
}
else if(HealthCare=”Platinum”)
{
window.alert(“You have chosen the platinum plan.”);
window.alert(“Your current balance is “);
window.alert(money2 – 400);
}
}
}
</script>
</body>
</html>

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@tracknutApr 04.2016 — "=" is an assignment operator, like a=1 (set a to 1)

"==" is a comparison operator, like if (a == 1) (is a equal to one)
Copy linkTweet thisAlerts:
@JTT2020authorApr 04.2016 — thanks that was all I needed.
Copy linkTweet thisAlerts:
@rootApr 05.2016 — When posting code, tags for making code stand out exist so please use them. See my signature ?
Copy linkTweet thisAlerts:
@JTT2020authorApr 06.2016 — OK its been a few days and I need help again, it says that i have an illegal token on line 82. Line 82 will be outlined with (( ))

window.alert("You have chosen the silver plan.");

window.alert("Your current balance is ");

window.alert(money2 - 200);

window.alert("Your dog runs into the street, and you run to get him. You are hit by a car and your leg is broken, it costs $200 to get the surgery to repair it.")

window.alert(money4 - 100);

window.alert("School is coming up and Timmy needs more clothes, however the cheapest uniform that the school supplies is $100 for a pack of 7. You also need to buy enough food to last you a week, costing you another $100.")

window.alert("Your current balance is")

window.alert(money5 - 200);

window.alert("Payday, due to you locating 40 hours of time to work you earned $330! Your current balance is")

window.alert(money7 + 330);

window.alert("Your kid falls and scrapes his knee, due to a lack of bandages you need to take him to your local patient first.")

window.alert("Your insurance covers this, allowing you to go without paying it.")

window.alert("Any insurance we listed would have covered this, showing that even people who are struggling to keep up have benefits.")

((window.alert("You feel a pain in your chest and you remember your family's history of heart problems. Do you get it checked out?") ))

var Doctor=window.prompt("Do you go to the hospital to get it checked out?")

if (Doctor=="Go to hospital")

{

window.alert("Your blood pressure is too high, it is suggested that you participate in activities outside of work to relieve stress.")

window.alert("your current balance is")

window.alert("money9 - 50)

}

else if (Doctor=="Do not go")

{

window.alert("Due to fear you choose not to go, but remain fearful as the pain continues.")

}

mind you I put spaces in there so there weren't three parenthesis in a row at the end of it. The single parenthesis before the space is supposed to be there.
Copy linkTweet thisAlerts:
@_DaniApr 06.2016 — I don't see your problem but next time you post a code please put it between these

[CODE]
Your Code Here
[/CODE]
Copy linkTweet thisAlerts:
@tracknutApr 06.2016 — The optional semicolons on JS drive me nuts, and you're using them sometimes, and sometimes not. I don't know what "normal" usage is, but I'd pick a flavor and stick with it.

Anyway, you have this statement:
<i>
</i>window.alert("money9 - 50)


Which can't be right with that single quote in it.
Copy linkTweet thisAlerts:
@JTT2020authorApr 06.2016 — There is a part that lists all the money but I didn't add that is it would require adding most of the code, but no that is not the problem.
×

Success!

Help @JTT2020 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 5.7,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...