• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

Switch statement for pdf js

Community Beginner ,
Jan 18, 2024 Jan 18, 2024

Copy link to clipboard

Copied

I am not a correct output for the following script:

 

var floor == this.getField("Floor Location").value;
var storeys == this.getField("Storeys").value;
var zero, oneStorey, twoStoreys, none, B, M, S;

if (storeys == "One storey") {
  storeys = oneStorey;
}
if (storeys == "Two storeys") {
  storeys = twoStoreys;
}

if (floor == "B") {
  floor = B;
}
if (floor == "M") {
  floor = M;
}
if (floor == "2nd") {
  floor = S;
}

switch (true) {

  case ((storeys == twoStoreys) && (floor == B)):
    event.value = "17";
    break;
  case ((storeys == twoStoreys) && (floor == M)):
    event.value = "11";
    break;
  case ((storeys == twoStoreys) && (floor == S)):
    event.value = "1";
    break;
   case ((storeys == oneStorey) && (floor == B)):
    event.value = "11";
    break;
  case ((storeys == oneStorey) && (floor == M)):
    event.value = "1";
    break;
  default:
        event.value = floor;
        break;}
 
Kk
TOPICS
JavaScript

Views

549

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Jan 19, 2024 Jan 19, 2024

Never mind I found the bug: the statement should be changed to 

"else if((storeys == "Two storeys") && (floor == "2nd"))
event.value = "1"

Thank you for putting me in the right track.

Votes

Translate

Translate
Community Expert ,
Jan 18, 2024 Jan 18, 2024

Copy link to clipboard

Copied

When you're assigning values to variables, you should use a single equal sign (=) instead of a double equal sign (==).

Why so many variables in this line: var zero, oneStorey, twoStoreys, none, B, M, S;

You don't use 'zero' or 'none' variable at all, you are setting floor variable to 'M' , 'B' or 'S' variable, but you didn't assign anything to them.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2024 Jan 19, 2024

Copy link to clipboard

Copied

Also, your use of the switch command doesn't make sense. Why not simply use if-else if?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 19, 2024 Jan 19, 2024

Copy link to clipboard

Copied

Because the switch statement I used is equivalent and simpler to in my script use than many "if" and "else" which could be confusing and there are too many combinations to deal with. Anyhow I tried that approach also and it does not work either. I am uploading the file for your own analysis.

Kk

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 19, 2024 Jan 19, 2024

Copy link to clipboard

Copied

I have made some corrections according to your comments but I still do not get the outputs I am looking for.

 

I am also attaching the pdf file so that you can see the outcome.

Kk

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2024 Jan 19, 2024

Copy link to clipboard

Copied

You've made it unnecessarily complicated (and incorrect).

See attached.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 19, 2024 Jan 19, 2024

Copy link to clipboard

Copied

Never mind I found the bug: the statement should be changed to 

"else if((storeys == "Two storeys") && (floor == "2nd"))
event.value = "1"

Thank you for putting me in the right track.

Kk

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 19, 2024 Jan 19, 2024

Copy link to clipboard

Copied

Thank you, that was a huge improvement over my script.

 

However, the case "else if((storeys == "Two storeys") && (floor == "S"))
event.value = "1";" does not respond. Could you help?

Thank you

Kk

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 19, 2024 Jan 19, 2024

Copy link to clipboard

Copied

I have made some corrections according to your comments but I still do not get the outputs I am looking for.

 

I am also attaching the pdf file so that you can see the outcome.

Kk

Kk

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2024 Jan 19, 2024

Copy link to clipboard

Copied

LATEST

So it's working well, or not?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines