6 kyu
Parse HTML/CSS Colors
154 of 2,744junthecoder
Loading description...
Fundamentals
Algorithms
Strings
Parsing
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Go Translation
Approved by someone
We need a clear explanation of how to do this. “preset Colors” it’s not clear how and what to do with it. C#
python new test framework is required. updated in this fork
Approved
I think it would help if there was a reference of RGB colors or its hexadecimal system on the instructions... It would be less confuse to someone who is not familiarized with that. But other than that, great kata!!
JS Node 18. should be enabled
Ruby 3.0 should be enabled
Description should be language-agnostic
wow.. amazing challenge.. really enjoyed this one !
Great kata! I had a lot of fun solving it.
One of the very fun kata that I've worked with so far! Thanks @lambda4fun
It's been a pleasure, thanks!!!
This comment has been hidden.
Not a kata issue, it's a problem with your code, use Question next time. Have you seen the error code you got in the sample tests?
There is your problem.
This comment has been hidden.
PRESET_COLORS
is a predefined map as the instructions say, it's not a part of JS core, it's a const/var defined for this kata.I think I need a little help with the "PRESET_COLORS" using Ruby. How does one use this?
It is a pre-defined hashmap in preloaded section, here's how you can use it!
Learned so much about web colors from this. My primary goal in coding is web programming, so I'm extra grateful.
Thought that PRESET_COLORS was a function, it is a dictionary, took me some time :)
The Haskell version should probably use the idiomatic way of importing from Data.Map:
I don't understand how to use PRESET_COLORS ,is there anyone can help me figure it out?
This is an object with keys. Try to use "console.log(PRESET_COLORS)" and you will understand.
For Python 3 - "print(PRESET_COLORS)"
@egregor82, when i console.log(PRESET_COLORS) it says PRESET_COLORS ISN'T DEFINED.
I thought that preset_color is one function instead of dict, which take me a long while to figure it out.........
I'm using matplotlib.colors.cnames in Python, but there's no color called "rebecca purple" or "sandy brown". Had to hard-code those...
Same!
Hello. I stuck on the finish. In Sublime my solution work fine(return object with correct keys), but here I get an error Cannot read property 'r' of undefined at every.channel ... Can someone help me?
I have same problem. I can't find out why :/
(JS) That one was getting me too. When I did a
console.log
on the predefined colors object... I noticed the keys were lower case, and I needed to convert the argument to lower.I have converted argument to lower, but still problem is not solved. In Sublime works great
This comment has been hidden.
This comment has been hidden.
Try adding the following line to the beginning of the function. Then you can determine what input is causing the error.
Your code fails for
blue
orBlUe
because you are checking the length first before the code logic flow enters theelse
statement, and obviously multiplying a string (l
) with an integer is invalid.This comment has been hidden.
Your code seems alright. Try it with a different browser.
thanks for replying. it pass all the test now with chrome. (but I do test with chrome before... but it doesnt work)
I seem to be stuck because of the format problem, like this: Expected: {r: 128, g: 255, b: 160}, instead got: '{r: 128, g: 255, b: 160}' Expected: {r: 51, g: 187, b: 119}, instead got: '{r: 51, g: 187, b: 119}'
Make sure the function returns an object, not a string.
Who can tell me how to delete my first solution :-( looks too stupid!!! I'm wrong in understanding the kata.
This Kata is interesting, but the predefined colors are too much :-)
I don´t understand how to this conversion: parse_html_color('LimeGreen') # => {'r': 50, 'g': 205, 'b': 50 }
Please read the 'Input' section in the description. You have to use the
PRESET_COLORS
map (aka dictionary). e.g.PRESET_COLORS['LimeGreen']
How do I use the PRESET_COLORS?? Is it to create a dictionary with all the rgb colors names and correposnding HEX and than access the hex by the name??
The
PRESET_COLORS
variable is predefined, so you can get the correspondent hex string by using a lower-cased color name as a key.I passed all test but still I am geting an error.
Time: 175ms Passed: 21 Failed: 0 Test Results: basic tests should parse 6-digit colors (11 Passed, 0 Failed) should parse 3-digit colors (10 Passed, 0 Failed) should parse preset colors STDERR: Traceback: in in parse_html_color ValueError: invalid literal for int() with base 16: 'LL'
Thanks for the help!!
Without your code I can't figure out what's wrong.
The keys of
PRESET_COLORS
are color names in lower-case string. Make sure you use lower-case string as a key.This comment has been hidden.
I agree with you. Now the tests accept colors regardless of the order of the keys. Thank you for the suggestion :)
This comment has been hidden.
String#downcase! is a destructive method, meaning it modifies the string itself but it doesn't necessarily returns the modified string.
You should run irb and try out the method.
You may also want to check the non-destructive version String#downcase (without the '!' suffix).
I enjoyed it. My solution is prbably very long, my brain is not working properly, but it was fun - thanks.
Thanks! I'm glad you enjoyed it :)
@lambda4fun
,Python 2 is unavailable because of
int.to_bytes
(which is only in Python 3).Thanks!
@zebulan
Thank you for the suggestion! I didn't know the way the available versions are selected.
Now Python 2 and 3 are both supported :)
@lambda4fun
,No problem! Thanks for fixing it so quickly!
This comment has been hidden.
That was a bug and it's fixed now. Thank you for reporting!
No worries. Glad that it helped! =]
Javascript translation kumitted.
'alr approved some time ago'
This is the first kata I authored. I would appreciate any advice or suggestions!
I think you did a great job.
I would have to say the PRESET_COLORS portion of the kata was confusing. I think it would have been great had that portion not been included, and if you wanted to keep the preset_colors than maybe a little more instruction for the different programming langauges.
That's just my 2 cents though. Thanks for adding another challange for everyone.