Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sirbuig opened this issue Feb 20, 2025 · 0 comments
Open

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

sirbuig opened this issue Feb 20, 2025 · 0 comments

Comments

@sirbuig
Copy link

sirbuig commented Feb 20, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant