If you're faced with an input box, like this:
+--------------+ Enter the price of the item, in dollars: | | +--------------+
Do you put the $ sign in, or not? Inevitably, some people will type a $ sign and others will leave it out. The instructions could be made clearer - but that won't help those people who never read instructions anyway.
A better solution is to write code that can handle the input whether it includes a $ sign or not.
So, write a simple function that converts a string representing a number into the number itself. Your function should be able to handle negatives!
money_value("12.34") => 12.34
money_value("-0.89") => -0.89
money_value(" .11") => 0.11
money_value("007") => 7
Want to propose a challenge idea for a future post? Email firstname.lastname@example.org with your suggestions!
Why Codewars is the best way to learn a new programming language!
Luke Garrigan -
Debugging - you’re doing it wrong. 10 techniques to find a bug in your code
How to build a todo app with React and Firebase Database
Rossano D'Angelo -
I Tried the Top 5 Coding Challenge Websites
Ashlee (she/her) -