from Hacker News

Show HN: CSS Speedrun – A small game to test and improve your CSS knowledge

by Vincenius on 1/17/22, 8:13 AM with 64 comments

  • by woolion on 1/17/22, 12:34 PM

    Nice project!

    It feels like it is missing ways to help you get to understand things on your own, so a bit more like a test than a real game. Maybe a codegolf scoring (number of characters) and/or semantic scoring (number of atomic expressions used) would help?

    As somebody who's doing frontend excessively rarely, it would feel more rewarding to see it compared to some good practices answers. Maybe store the results so you could display the most frequent answers in a future iteration?

    Took 16 minutes, trying to understand more than to speedrun. Btw, link of hint 10 is broken (there's an extraneous comma).

    The dynamic selection dots are quite neatly done. I found it quite fun and it seems like there are many ways to add interesting features!

  • by iheredia on 1/17/22, 9:32 AM

    * Spoiler *

    The use of `:not` is way more powerful that I usually remember. For example, the second exercise asks to select all the <p> except the one with class="foo"

      <div>
        <p></p>
        <p class="foo"></p>
        <p></p>
        <p></p>
      </div>
    
    This can be done with

      p:not(.foo)
    
    But also by selecting every thing that we don't want and then negating that.

      :not(div, .foo)
  • by 414owen on 1/17/22, 10:59 AM

    Huh, I wrote a very similar game a while ago. Select elements with CSS selectors to get to the next level: https://select.pink/

    Mine displays the elements as nested blocks, instead of printing a tree.

  • by chrismorgan on 1/17/22, 11:03 AM

    Minor quibble: level 6’s code uses </input>, which is invalid in HTML syntax (though harmless): <input> is a void element, meaning it can’t have any children and has no end tag.

    (You could write <input/>, the old XML syntax for self-closing tags, but I strongly recommend against doing that because it teaches a wrong mental model: that trailing slash is permitted in HTML syntax on void elements for XHTML compatibility but does not close an element: it’s just ignored.)

  • by TomAnthony on 1/17/22, 11:14 AM

    This was fun. :)

    I feel like there should be another scoring axis rather than just time. I think selector length would be wrong, but something like selector complexity, or how robust the selector is to updates.

    I scored 3m 50s, but felt like some of my selectors were a bit 'dirty'.

  • by Nadya on 1/17/22, 6:21 PM

    4:22 - I got stuck on the ID one because I felt like I was meant to do something than select each one individually. I also got stuck on :enabled and ended up writing something dumb in retrospect. Some of my selectors were quite hacky in the name of speed though.

    It would have been nice to see what the intended solutions after because otherwise I have no way of finding out that using :enabled was the intended way and not input:not(disabled), button:not(disabled). Realized after I could have used an :is there but I don't use :is often in work due to browser support for IE so it didn't cross my mind at the time. It would also be nice to see that #one, #three, #five, #nine (or whatever the ID's where for that puzzle) was indeed the "intended" answer as a kind of trick question.

    Without reading HN I would not have learned I was meant to use :enabled.

  • by superasn on 1/17/22, 10:46 AM

    Very fun game. There needs to be a golf mode where you get the right answer with the shortest selector just for fun!
  • by mcv on 1/17/22, 10:15 AM

    7:22, but I needed a lot of hints. And many of my selectors were rather arbitrary lists of unconnected selectors. I feel like there should be better answers than the ones I gave.
  • by grenoire on 1/17/22, 9:57 AM

    5:25, not terrible. Couple of them I was able to brute-force, some of them I realised the easy solution as I was brute-forcing! It's fun, :not(...) is godsend.
  • by mrjay42 on 1/17/22, 8:15 PM

    I solved level 4 using is() But I am sure there's a better way with the any of the attribute selectors (https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_s...). But I did not find how to do it :'(
  • by tiffanyh on 1/17/22, 9:45 PM

    Love the project.

    Wish it had the answer as well, not just hint.

  • by codeptualize on 1/17/22, 8:45 AM

    That was honestly quite fun. I did 08:04:7
  • by emaro on 1/17/22, 1:47 PM

    Nice! I completed it in 05:40:2. Would be fun to have more levels and/or scoring criteria.
  • by Zekio on 1/17/22, 8:33 AM

    More fun than I expected, though I seem to have forgotten how IDs are a thing you can target, everything is classes these days, so only got a time of 10:28 due to spending minutes writing an insane selector rather than ID, ID
  • by 255 on 1/17/22, 11:16 AM

    I like it good job!!

    I would extend its usefulness by rewarding shorter answers, as you could cheat a lot by using long nth-child selectors for everything which is basically unusable in actual stylesheets

  • by jdefelice on 1/17/22, 11:56 AM

    I got stuck on level 7 because I forgot id selectors where a thing.
  • by sam_goody on 1/17/22, 6:18 PM

    Took me 8 minutes, but I felt that my answers for some were sub-optimal.

    It would be good if there was a way I could have seen other users' answers, so I could learn new tricks.

  • by partiallypro on 1/17/22, 4:54 PM

    I know most rules that exist but don't always remember them off the top of my head so I look them up. That being said, I was not actually aware of :not
  • by nayuki on 1/17/22, 4:46 PM

    I used the child combinator (>) and adjacent sibling combinator (+) a lot. I think these aren't used much in real-world code?
  • by MrPatan on 1/17/22, 11:16 AM

    4:26, but there were a lot of commas sometimes...
  • by 0lucky on 1/17/22, 11:58 AM

    This is great! I learned a lot in 28 mins :p
  • by soperj on 1/17/22, 9:56 PM

    This was really good. I knew all the rules, but took me a bit to remember each of them. Did it in 10 minutes.
  • by proee on 1/17/22, 9:37 PM

    This is a nice project. Is there anything similar for learning to program?
  • by throwoutway on 1/17/22, 3:16 PM

    This is a nice project. Could you talk about how you made the game?