Which of the following code statements would BEST correct the issue?

A developer is troubleshooting code in an application. The code is supposed to return the word “vegetables” if the category id is only 2. However the code is returning vegetables for all values except category id 1. Which of the following code statements would BEST correct the issue?
A. If category id = 1 then ‘Fruit’
Else ‘Vegetables’
B. If category id = 1 then ‘Fruit’
Else ‘Vegetables’
C. If category id <> 1 then ‘Vegetables’
Else ‘Fruit’
D. If category id = 1 then ‘Fruit’
Else if category id >= 2 then ‘Vegetables’
Else ‘Candy’

comptia-exams

One thought on “Which of the following code statements would BEST correct the issue?

  1. Actually the answer IS supposed to be B

    The problem is answer B is Incomplete and it was supposed to be listed as:
    B. If category id = 1 then ‘Fruit’
    Else if category id = 2 then ‘Vegetables’
    Else ‘Candy’

    D. Has a CODE ERROR in it, HERE it would technically be the closest, but it’s incorrect.

    If you google this same question you will be linked to another source that has this same question with answer B as being correct as the Correct Complete Answer.

  2. I’m not so sure, I checked another reference that shows same question but still shows answer B. However answer B elsewhere is more complete. The correct answer should technically be:

    B. If category id = 1 then ‘Fruit’
    Else if category id = 2 then ‘Vegetables’
    Else ‘Candy’

    and not

    D. If category id = 1 then ‘Fruit’
    Else if category id >= 2 then ‘Vegetables’
    Else ‘Candy’

    The problem with answer D is a mistype in code it seems with the: >=2

    You may want to check this reference:
    https://www.examtopics.com/exams/comptia/fc0-u61/view/32/
    Question 160

    Answer is B.

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.