CompTIA ITF+ (FC0-U61) — Question 114

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?

Answer options

Correct answer: B

Explanation

The correct answer is B because it explicitly checks if the category id is 1, then returns 'Fruit', and if it is 2, it returns 'Vegetables', which aligns with the intended functionality. The other options either do not properly handle the condition for the category id of 2 or incorrectly categorize other values.