Correct syntax for if statements in Haskell

haskell, if-statement

Solution

You can't have the `let` inside the conditionals, otherwise the variable `x` won't be available in the following expression that needs it.

In your case, you don't even need the let-binding because you just want to return the string immediately, so you can just do:

myScore x = 
    if x > 90 then "You got a A"
    else if 80 < x && x < 90 then "you got a B"
    else if 70 < x && x < 80 then "You got a C"
    else if 60 < x && x < 70 then "you got a D"
    else "You got a F"

Also note, you can't do `80<x<90` - you have to combine two expressions with the `&&` operator..

The above can be further simplified syntactically, using guards:

myScore x
    | x > 90 = "You got a A"
    | x > 80 = "you got a B"
    | x > 70 = "You got a C"
    | x > 60 = "you got a D"
    | otherwise = "You got a F"

Problem

The only input you need is the grade number that you get. This is what I have so far. ``` myScore x = if x > 90 then let x = "You got a A" if 80 < x < 90 then let x = "you got a B" if 70 < x < 80 then let x = "You got a C" if 60 < x < 90 then let x = "you got a D" else let x = "You got a F" ``` This gives me an error "parse error on input `if' ", I also tried: ``` myScore x = (if x > 90 then "You got an A" | if 80 < x < 90 then "You got a B" | if 70 < x < 80 then "You got a D" | if 60 < x < 70 then "You got a D" else "You got a F") ``` but that didn't work either.

Original source