#I need help with Betty's Bike Shop in Gleam

33 messages ยท Page 1 of 1 (latest)

covert kiln
#

The first 2 test failures I have are because I don't know how to add a British pound sign in front of the price in pounds_to_string. The other 2 are because I don't know how to write pence_to_pounds. If I try something like pence / 100 or pence /. 100, it just breaks the code even worse. I've just left that function as todo here.

import gleam/float
import gleam/string

pub fn pence_to_pounds(pence: Int) -> Float {
  todo
}

pub fn pounds_to_string(pounds: Float) -> String {
  float.to_string(pounds)
}```
west vale
#

For 1, copy/paste ยฃ

#

Google says, There are 100 pennies, or pence, to the pound.

#

If I try something like pence / 100 or pence /. 100, it just breaks the code even worse.
It would be helpful to see the complete code and the complete error message with whatever you tried ๐Ÿ™‚

covert kiln
#

Here's what happens when I try pence / 100.

  โ”Œโ”€ src/bettys_bike_shop.gleam:1:1
  โ”‚
1 โ”‚ import gleam/int
  โ”‚ ^^^^^^^^^^^^^^^^ This imported module is never used
Hint: You can safely remove it.
warning: Unused imported module
  โ”Œโ”€ src/bettys_bike_shop.gleam:3:1
  โ”‚
3 โ”‚ import gleam/string
  โ”‚ ^^^^^^^^^^^^^^^^^^^ This imported module is never used
Hint: You can safely remove it.
error: Type mismatch
  โ”Œโ”€ src/bettys_bike_shop.gleam:6:3
  โ”‚
6 โ”‚   pence / 100
  โ”‚   ^^^^^^^^^^^
The type of this returned value doesn't match the return type
annotation of this function.
Expected type:
    Float
Found type:
    Int```
west vale
#

There are some very helpful warning/error messages there. You should read them, understand them, and make changes based on what they are telling you.

#

Did you try to read and udnerstand them?

covert kiln
#

I understand that I'm supposed to use gleam/int gleam/float and gleam/string at some point, and I understand that pence / 100 is expecting pence to be a Float.

west vale
#

Can you fix those?

covert kiln
#

No.

west vale
#

Why not?

#

I understand that pence / 100 is expecting pence to be a Float
Can you do something about this?

covert kiln
#

๐Ÿคทโ€โ™‚๏ธ It's an Int. It's supposed to be an Int.

west vale
#

Right. Pence is an Int.

#

But you're trying to use it to calculate something else -- a not-Int

#

Are pounds an Int?

covert kiln
#

They are a Float.

west vale
#

So how would you get from an Int pence to Float pounds?

covert kiln
#

I don't know. The exercise instructions didn't give me a function for that.

west vale
#

What steps do you suppose you'd need to take?

#

Assuming you can find any functions you need using Google and the Gleam docs ๐Ÿ˜‰

west vale
#

So ... you'd want to convert the Int to a Float first? And you found the docs that shows how to do it?

covert kiln
#

Yes.

west vale
#

There you go. Step 1: figure out what's needed (convert Int to Float). Step 2: find a way to do it.

covert kiln
#

I knew that. I just needed to know the function for it.

west vale
#

Ah. So your question all along was, "what function do I used to convert an Int to a Float"?

#

I didn't realize you were asking for help finding a function ๐Ÿ™‚ In the future, it might help to be more clear and specific about what you need help with.

I don't know how to write pence_to_pounds. If I try something like pence / 100 or pence /. 100, it just breaks the code even worse.
That says "I don't know what to do" without a whole lot of specifics of what you're stuck on.

pliant lindenBOT
#

If everything is resolved, we ask that the person who posted the request react to the top/original post with a :white_check_mark: (:white_check_mark:). This indicates to others that this issue has been resolved and locks the thread.
If all the tests pass and you want to further improve your solution, we encourage you to use the "Request a Code Review" feature on the website!

covert kiln
#

Ok, what about the pound sign? To be clear, I'm not asking "how do I type a pound sign? It's not on my keyboard.", I'm asking "What is the function I need to put it in front of the price?".

west vale
#

You'd attach it the same way you would join any two strings. Can you join "a" and "b"?

covert kiln
#

"ยฃ" + float.to_string(pounds)?

west vale
#

Ask the tests, not the human ๐Ÿ˜