Skip to content

Add additional comment to explain 03_if/if3 solution #2211

Open
@sirbuig

Description

@sirbuig

I think 03_if/if3.rs is a bit ambiguous. The code to be modified looks like this:

// TODO: Fix the compiler error in the statement below.
    let identifier = if animal == "crab" {
        1
    } else if animal == "gopher" {
        2.0
    } else if animal == "snake" {
        3
    } else {
        "Unknown"
    };

which is intuitively indicating to change "Unknown" to an unused identifier, however it still won't work because the compiler will continue prompting for changes until 2.0 is replaced with 2.

Personally it took me a while to figure it out, and that's not the problem, but when I checked the official solution:

let identifier = if animal == "crab" {
        1
    } else if animal == "gopher" {
        2
    } else if animal == "snake" {
        3
    } else {
        // Any unused identifier.
        4
    };

the only change mentioned is from Unknown to 4, but there's no explanation that 2.0 must also be changed to 2. I think adding a comment to clarify the necessary type consistency would be very helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions