nerdexam
CompTIA

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

Software Development

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)
  • A
    8% (5)
  • B
    77% (46)
  • C
    3% (2)
  • D
    12% (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.

AIf category id = 1 then 'Fruit'

This choice is identical to choice B and provides the same potential correction.

BIf category id = 1 then 'Fruit'Correct

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.

CIf category id <> 1 then 'Vegetables'

If category id <> 1 then 'Vegetables' describes the current faulty logic where 'vegetables' is returned for all IDs except 1, not a correction.

DIf category id = 1 then 'Fruit'

This choice is identical to choice B and provides the same potential correction.

Concept tested: Conditional programming logic correction

Topics

#conditional logic#debugging#programming syntax

Community Discussion

No community discussion yet for this question.

Full FC0-U61 Practice