Interactive multiple choice code
up vote
0
down vote
favorite
This isn't so much, HOW do I make it work, as this code works, rather how could I make it better. The way this code works is it guides a person to the correct answer by getting "Yes", "No" or "I don't know" (in some cases from the person).
It's intended to run in HTML5/JavaScript (kind of like an online interactive guide). This code actually works, but it uses the JavaScript "prompt" for the input, and frankly, it's pretty ugly. Any suggestions on how to make it either look or work better?
First the JavaScript, as it's the main engine:
function mc1() {
var n = prompt("Do you have Medicare benefits (Y=Yes, N=No, I=I don't know)", " ");
if( n == "Y"){
mcs2();
}
else if (n="N"){
mcs1a();
}
else if (n="I"){
mcs1b();
}
else {
alert("Enter a valid choice Y,N or I!");
mc1();
}
}
function mcs1a(){
var n1=prompt("Have you applied and been denied Medicare Coverage (Y= Yes, N= No, I = I don't know)", "");
if (n1=="Y"){
mc3a();
}
else if (n1=="N"){
mc2b();
}
else if (n1=="I"){
mc2b();
}
else {
alert("Enter a valid choice: Y, N or I!");
}
}
function mcs1b(){
alert("Refer to Social Security Administration to check status, (CODE E01M1)!");
}
function mcs2(){
var n2=prompt("Do you have Medicare Part A AND B ( Y=Yes, N=No, I=I don't know)","");
if (n2=="Y"){
mcs3();
}
if (n2=="N"){
alert("Refer to Social Security to apply for the other part (Code E01M1)!");
}
if (n2=="I"){
alert("Refer to Social Security Administration to check status (Code E01M1)!");
}
else {
alert("Enter a valid choice: Y, N, or I!");
}
}
function mcs3(){
var n3=prompt("Would you like to apply for HF MEdicare (Y=Yes, N=No)","");
if (n3=="Y"){
mcs4a();
}
if (n3=="N"){
mcs4();
}
else {
alert("Enter a valid choice: Y or N!");
}
}
function mcs4(){
var n4=prompt("Do you have a caretaker relative who claims you on their taxes (Y=Yes, N=No)","");
if (n4=="Y"){
alert("Follow standard prequalification with caretaker relative as the income");
}
if (n4=="N"){
alert("Refer to the HRA/LDSS/SLDSS to apply for benefits (CODE E01H)");
}
else {
alert("Enter a valid choice: Y or N!");
}
}
function mcs4a(){
alert("Warm transfer to Medicare Advertising to apply for HealthFirst Medicare (Code WTS)");}
mc1();
<html>
<head />
<body>
<script src="testdrop.js"></script>
</body>
</html>
javascript html5
New contributor
add a comment |
up vote
0
down vote
favorite
This isn't so much, HOW do I make it work, as this code works, rather how could I make it better. The way this code works is it guides a person to the correct answer by getting "Yes", "No" or "I don't know" (in some cases from the person).
It's intended to run in HTML5/JavaScript (kind of like an online interactive guide). This code actually works, but it uses the JavaScript "prompt" for the input, and frankly, it's pretty ugly. Any suggestions on how to make it either look or work better?
First the JavaScript, as it's the main engine:
function mc1() {
var n = prompt("Do you have Medicare benefits (Y=Yes, N=No, I=I don't know)", " ");
if( n == "Y"){
mcs2();
}
else if (n="N"){
mcs1a();
}
else if (n="I"){
mcs1b();
}
else {
alert("Enter a valid choice Y,N or I!");
mc1();
}
}
function mcs1a(){
var n1=prompt("Have you applied and been denied Medicare Coverage (Y= Yes, N= No, I = I don't know)", "");
if (n1=="Y"){
mc3a();
}
else if (n1=="N"){
mc2b();
}
else if (n1=="I"){
mc2b();
}
else {
alert("Enter a valid choice: Y, N or I!");
}
}
function mcs1b(){
alert("Refer to Social Security Administration to check status, (CODE E01M1)!");
}
function mcs2(){
var n2=prompt("Do you have Medicare Part A AND B ( Y=Yes, N=No, I=I don't know)","");
if (n2=="Y"){
mcs3();
}
if (n2=="N"){
alert("Refer to Social Security to apply for the other part (Code E01M1)!");
}
if (n2=="I"){
alert("Refer to Social Security Administration to check status (Code E01M1)!");
}
else {
alert("Enter a valid choice: Y, N, or I!");
}
}
function mcs3(){
var n3=prompt("Would you like to apply for HF MEdicare (Y=Yes, N=No)","");
if (n3=="Y"){
mcs4a();
}
if (n3=="N"){
mcs4();
}
else {
alert("Enter a valid choice: Y or N!");
}
}
function mcs4(){
var n4=prompt("Do you have a caretaker relative who claims you on their taxes (Y=Yes, N=No)","");
if (n4=="Y"){
alert("Follow standard prequalification with caretaker relative as the income");
}
if (n4=="N"){
alert("Refer to the HRA/LDSS/SLDSS to apply for benefits (CODE E01H)");
}
else {
alert("Enter a valid choice: Y or N!");
}
}
function mcs4a(){
alert("Warm transfer to Medicare Advertising to apply for HealthFirst Medicare (Code WTS)");}
mc1();
<html>
<head />
<body>
<script src="testdrop.js"></script>
</body>
</html>
javascript html5
New contributor
"message": "Uncaught ReferenceError: mc2b is not defined",
– hjpotter92
53 mins ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This isn't so much, HOW do I make it work, as this code works, rather how could I make it better. The way this code works is it guides a person to the correct answer by getting "Yes", "No" or "I don't know" (in some cases from the person).
It's intended to run in HTML5/JavaScript (kind of like an online interactive guide). This code actually works, but it uses the JavaScript "prompt" for the input, and frankly, it's pretty ugly. Any suggestions on how to make it either look or work better?
First the JavaScript, as it's the main engine:
function mc1() {
var n = prompt("Do you have Medicare benefits (Y=Yes, N=No, I=I don't know)", " ");
if( n == "Y"){
mcs2();
}
else if (n="N"){
mcs1a();
}
else if (n="I"){
mcs1b();
}
else {
alert("Enter a valid choice Y,N or I!");
mc1();
}
}
function mcs1a(){
var n1=prompt("Have you applied and been denied Medicare Coverage (Y= Yes, N= No, I = I don't know)", "");
if (n1=="Y"){
mc3a();
}
else if (n1=="N"){
mc2b();
}
else if (n1=="I"){
mc2b();
}
else {
alert("Enter a valid choice: Y, N or I!");
}
}
function mcs1b(){
alert("Refer to Social Security Administration to check status, (CODE E01M1)!");
}
function mcs2(){
var n2=prompt("Do you have Medicare Part A AND B ( Y=Yes, N=No, I=I don't know)","");
if (n2=="Y"){
mcs3();
}
if (n2=="N"){
alert("Refer to Social Security to apply for the other part (Code E01M1)!");
}
if (n2=="I"){
alert("Refer to Social Security Administration to check status (Code E01M1)!");
}
else {
alert("Enter a valid choice: Y, N, or I!");
}
}
function mcs3(){
var n3=prompt("Would you like to apply for HF MEdicare (Y=Yes, N=No)","");
if (n3=="Y"){
mcs4a();
}
if (n3=="N"){
mcs4();
}
else {
alert("Enter a valid choice: Y or N!");
}
}
function mcs4(){
var n4=prompt("Do you have a caretaker relative who claims you on their taxes (Y=Yes, N=No)","");
if (n4=="Y"){
alert("Follow standard prequalification with caretaker relative as the income");
}
if (n4=="N"){
alert("Refer to the HRA/LDSS/SLDSS to apply for benefits (CODE E01H)");
}
else {
alert("Enter a valid choice: Y or N!");
}
}
function mcs4a(){
alert("Warm transfer to Medicare Advertising to apply for HealthFirst Medicare (Code WTS)");}
mc1();
<html>
<head />
<body>
<script src="testdrop.js"></script>
</body>
</html>
javascript html5
New contributor
This isn't so much, HOW do I make it work, as this code works, rather how could I make it better. The way this code works is it guides a person to the correct answer by getting "Yes", "No" or "I don't know" (in some cases from the person).
It's intended to run in HTML5/JavaScript (kind of like an online interactive guide). This code actually works, but it uses the JavaScript "prompt" for the input, and frankly, it's pretty ugly. Any suggestions on how to make it either look or work better?
First the JavaScript, as it's the main engine:
function mc1() {
var n = prompt("Do you have Medicare benefits (Y=Yes, N=No, I=I don't know)", " ");
if( n == "Y"){
mcs2();
}
else if (n="N"){
mcs1a();
}
else if (n="I"){
mcs1b();
}
else {
alert("Enter a valid choice Y,N or I!");
mc1();
}
}
function mcs1a(){
var n1=prompt("Have you applied and been denied Medicare Coverage (Y= Yes, N= No, I = I don't know)", "");
if (n1=="Y"){
mc3a();
}
else if (n1=="N"){
mc2b();
}
else if (n1=="I"){
mc2b();
}
else {
alert("Enter a valid choice: Y, N or I!");
}
}
function mcs1b(){
alert("Refer to Social Security Administration to check status, (CODE E01M1)!");
}
function mcs2(){
var n2=prompt("Do you have Medicare Part A AND B ( Y=Yes, N=No, I=I don't know)","");
if (n2=="Y"){
mcs3();
}
if (n2=="N"){
alert("Refer to Social Security to apply for the other part (Code E01M1)!");
}
if (n2=="I"){
alert("Refer to Social Security Administration to check status (Code E01M1)!");
}
else {
alert("Enter a valid choice: Y, N, or I!");
}
}
function mcs3(){
var n3=prompt("Would you like to apply for HF MEdicare (Y=Yes, N=No)","");
if (n3=="Y"){
mcs4a();
}
if (n3=="N"){
mcs4();
}
else {
alert("Enter a valid choice: Y or N!");
}
}
function mcs4(){
var n4=prompt("Do you have a caretaker relative who claims you on their taxes (Y=Yes, N=No)","");
if (n4=="Y"){
alert("Follow standard prequalification with caretaker relative as the income");
}
if (n4=="N"){
alert("Refer to the HRA/LDSS/SLDSS to apply for benefits (CODE E01H)");
}
else {
alert("Enter a valid choice: Y or N!");
}
}
function mcs4a(){
alert("Warm transfer to Medicare Advertising to apply for HealthFirst Medicare (Code WTS)");}
mc1();
<html>
<head />
<body>
<script src="testdrop.js"></script>
</body>
</html>
function mc1() {
var n = prompt("Do you have Medicare benefits (Y=Yes, N=No, I=I don't know)", " ");
if( n == "Y"){
mcs2();
}
else if (n="N"){
mcs1a();
}
else if (n="I"){
mcs1b();
}
else {
alert("Enter a valid choice Y,N or I!");
mc1();
}
}
function mcs1a(){
var n1=prompt("Have you applied and been denied Medicare Coverage (Y= Yes, N= No, I = I don't know)", "");
if (n1=="Y"){
mc3a();
}
else if (n1=="N"){
mc2b();
}
else if (n1=="I"){
mc2b();
}
else {
alert("Enter a valid choice: Y, N or I!");
}
}
function mcs1b(){
alert("Refer to Social Security Administration to check status, (CODE E01M1)!");
}
function mcs2(){
var n2=prompt("Do you have Medicare Part A AND B ( Y=Yes, N=No, I=I don't know)","");
if (n2=="Y"){
mcs3();
}
if (n2=="N"){
alert("Refer to Social Security to apply for the other part (Code E01M1)!");
}
if (n2=="I"){
alert("Refer to Social Security Administration to check status (Code E01M1)!");
}
else {
alert("Enter a valid choice: Y, N, or I!");
}
}
function mcs3(){
var n3=prompt("Would you like to apply for HF MEdicare (Y=Yes, N=No)","");
if (n3=="Y"){
mcs4a();
}
if (n3=="N"){
mcs4();
}
else {
alert("Enter a valid choice: Y or N!");
}
}
function mcs4(){
var n4=prompt("Do you have a caretaker relative who claims you on their taxes (Y=Yes, N=No)","");
if (n4=="Y"){
alert("Follow standard prequalification with caretaker relative as the income");
}
if (n4=="N"){
alert("Refer to the HRA/LDSS/SLDSS to apply for benefits (CODE E01H)");
}
else {
alert("Enter a valid choice: Y or N!");
}
}
function mcs4a(){
alert("Warm transfer to Medicare Advertising to apply for HealthFirst Medicare (Code WTS)");}
mc1();
<html>
<head />
<body>
<script src="testdrop.js"></script>
</body>
</html>
function mc1() {
var n = prompt("Do you have Medicare benefits (Y=Yes, N=No, I=I don't know)", " ");
if( n == "Y"){
mcs2();
}
else if (n="N"){
mcs1a();
}
else if (n="I"){
mcs1b();
}
else {
alert("Enter a valid choice Y,N or I!");
mc1();
}
}
function mcs1a(){
var n1=prompt("Have you applied and been denied Medicare Coverage (Y= Yes, N= No, I = I don't know)", "");
if (n1=="Y"){
mc3a();
}
else if (n1=="N"){
mc2b();
}
else if (n1=="I"){
mc2b();
}
else {
alert("Enter a valid choice: Y, N or I!");
}
}
function mcs1b(){
alert("Refer to Social Security Administration to check status, (CODE E01M1)!");
}
function mcs2(){
var n2=prompt("Do you have Medicare Part A AND B ( Y=Yes, N=No, I=I don't know)","");
if (n2=="Y"){
mcs3();
}
if (n2=="N"){
alert("Refer to Social Security to apply for the other part (Code E01M1)!");
}
if (n2=="I"){
alert("Refer to Social Security Administration to check status (Code E01M1)!");
}
else {
alert("Enter a valid choice: Y, N, or I!");
}
}
function mcs3(){
var n3=prompt("Would you like to apply for HF MEdicare (Y=Yes, N=No)","");
if (n3=="Y"){
mcs4a();
}
if (n3=="N"){
mcs4();
}
else {
alert("Enter a valid choice: Y or N!");
}
}
function mcs4(){
var n4=prompt("Do you have a caretaker relative who claims you on their taxes (Y=Yes, N=No)","");
if (n4=="Y"){
alert("Follow standard prequalification with caretaker relative as the income");
}
if (n4=="N"){
alert("Refer to the HRA/LDSS/SLDSS to apply for benefits (CODE E01H)");
}
else {
alert("Enter a valid choice: Y or N!");
}
}
function mcs4a(){
alert("Warm transfer to Medicare Advertising to apply for HealthFirst Medicare (Code WTS)");}
mc1();
<html>
<head />
<body>
<script src="testdrop.js"></script>
</body>
</html>
javascript html5
javascript html5
New contributor
New contributor
edited 1 hour ago
Jamal♦
30.2k11115226
30.2k11115226
New contributor
asked 1 hour ago
KoshVorlon
12
12
New contributor
New contributor
"message": "Uncaught ReferenceError: mc2b is not defined",
– hjpotter92
53 mins ago
add a comment |
"message": "Uncaught ReferenceError: mc2b is not defined",
– hjpotter92
53 mins ago
"message": "Uncaught ReferenceError: mc2b is not defined",
– hjpotter92
53 mins ago
"message": "Uncaught ReferenceError: mc2b is not defined",
– hjpotter92
53 mins ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Indent your code and watch the newlines and spacing.
There is a difference between == and =, you use both in mc1().
The names of your functions are not explaining what the functions do.
You might want to allow lowercase letters as input, this is a design choice. Your prompt specifies capitals, so it should suffice.
As an interactive guide, HTML/JS buttons might be better, but that is more a question for https://ux.stackexchange.com/
New contributor
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
KoshVorlon is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f209740%2finteractive-multiple-choice-code%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Indent your code and watch the newlines and spacing.
There is a difference between == and =, you use both in mc1().
The names of your functions are not explaining what the functions do.
You might want to allow lowercase letters as input, this is a design choice. Your prompt specifies capitals, so it should suffice.
As an interactive guide, HTML/JS buttons might be better, but that is more a question for https://ux.stackexchange.com/
New contributor
add a comment |
up vote
0
down vote
Indent your code and watch the newlines and spacing.
There is a difference between == and =, you use both in mc1().
The names of your functions are not explaining what the functions do.
You might want to allow lowercase letters as input, this is a design choice. Your prompt specifies capitals, so it should suffice.
As an interactive guide, HTML/JS buttons might be better, but that is more a question for https://ux.stackexchange.com/
New contributor
add a comment |
up vote
0
down vote
up vote
0
down vote
Indent your code and watch the newlines and spacing.
There is a difference between == and =, you use both in mc1().
The names of your functions are not explaining what the functions do.
You might want to allow lowercase letters as input, this is a design choice. Your prompt specifies capitals, so it should suffice.
As an interactive guide, HTML/JS buttons might be better, but that is more a question for https://ux.stackexchange.com/
New contributor
Indent your code and watch the newlines and spacing.
There is a difference between == and =, you use both in mc1().
The names of your functions are not explaining what the functions do.
You might want to allow lowercase letters as input, this is a design choice. Your prompt specifies capitals, so it should suffice.
As an interactive guide, HTML/JS buttons might be better, but that is more a question for https://ux.stackexchange.com/
New contributor
New contributor
answered 45 mins ago
user2966394
213
213
New contributor
New contributor
add a comment |
add a comment |
KoshVorlon is a new contributor. Be nice, and check out our Code of Conduct.
KoshVorlon is a new contributor. Be nice, and check out our Code of Conduct.
KoshVorlon is a new contributor. Be nice, and check out our Code of Conduct.
KoshVorlon is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f209740%2finteractive-multiple-choice-code%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
"message": "Uncaught ReferenceError: mc2b is not defined",
– hjpotter92
53 mins ago