FC0-U61 · Question #450
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 excep
The correct answer is B. If category id = 1 then 'Fruit'. The problem states the code incorrectly returns 'vegetables' for all IDs except 1, but should only do so for ID 2, and implicitly 'Fruit' for ID 1. Establishing the specific condition 'If category id = 1 then 'Fruit'' is a correct and necessary step towards implementing the desir
Question
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?
Options
- AIf category id = 1 then 'Fruit'
- BIf category id = 1 then 'Fruit'
- CIf category id <> 1 then 'Vegetables'
- DIf category id = 1 then 'Fruit'
How the community answered
(60 responses)- A8% (5)
- B77% (46)
- C3% (2)
- D12% (7)
Why each option
The problem states the code incorrectly returns 'vegetables' for all IDs except 1, but should only do so for ID 2, and implicitly 'Fruit' for ID 1. Establishing the specific condition 'If category id = 1 then 'Fruit'' is a correct and necessary step towards implementing the desired conditional logic.
This choice is identical to choice B and provides the same potential correction.
To correct the issue where 'vegetables' is returned too broadly, specifically defining the output for `category id = 1` as 'Fruit' ensures that this condition is handled correctly and is not inadvertently caught by a broad 'vegetables' assignment. This statement is a fundamental building block for implementing precise conditional logic like an `if-else if` structure, correctly segregating the 'Fruit' category.
If category id <> 1 then 'Vegetables' describes the current faulty logic where 'vegetables' is returned for all IDs except 1, not a correction.
This choice is identical to choice B and provides the same potential correction.
Concept tested: Conditional programming logic correction
Topics
Community Discussion
No community discussion yet for this question.