DEV Community

Cover image for A basis for a coding interview using "FizzBuzz" only⁉- 8 challenges for beginners AND Pros [with a twist for Pros! 😱]

A basis for a coding interview using "FizzBuzz" only⁉- 8 challenges for beginners AND Pros [with a twist for Pros! 😱]

GrahamTheDev on July 11, 2021

FizzBuzz is a mental arithmetic game that got turned into a popular interview question. But what if we took the principle and created 8 different c...
Collapse
 
siddharthshyniben profile image
Siddharth

Done!

It's still undergoing refactoring and extra credit exercises, but I'm kinda busy (I got exams!). It might be done in 24 hours.

Collapse
 
grahamthedev profile image
GrahamTheDev • Edited

When you have tidied up (and fixed a naming bug, hint hint wordmap and wordMap) then let me know!

After an initial look though it looks good ❤, but I won't test properly until you tell me to!

P.s. my instructions might not have been clear enough but there should be no "decrease" button, the "next" button coupled with the checkbox should dictate direction. I will check that the instructions don't cause confusion there.

Collapse
 
siddharthshyniben profile image
Siddharth • Edited

You can consider it done! After a lot of testing and stuff, it seems bug free. Test it out and tell me if there's any problems.

About my attempt

Challenge 1: Was not very hard, just had to reimplement division, which was pretty easy
Challenge 2: Still pretty easy. Just had to add some event listeners. This was made even more easy by the fact that my fizzbuzz function only checked a single number.
Challenge 3: Just had to add a few lines
Challenge 4: This was easy at first, but would ultimately be the biggest problem and I had to rewrite it.
Challenge 5: That was literally what I was doing. I was just logging to the console outside my fizzbuzz function. Just needed to change a few lines.
Challenge 6: Easy again, because my fizzbuzz function just checked one number, and I just had to change the numbers in the recursion I was doing earlier
Challenge 7: Easy, but this was where I made 99% of my silly mistakes (I was trying to reverse recursion, until I realized I need to pass in the minimum). This part took the most time.
Challenge 8: This was pretty easy, because I'm used to manipulating objects in this manner.

What I learned:

  • Open/Closed principle is awesome!
  • Recursion is not as easy as I thought (but still pretty easy)
  • I make billions of silly mistakes (why didn't that variable change? of course i didn't assign any value to it)

PS: These challenges are awesome, would love it if you make more! I might even make a challenge myself! (I did once but no one answered. I guess it was too hard)

Collapse
 
siddharthshyniben profile image
Siddharth

Hmm the decrease button came up a accidentally because of my initial confusion, and I decided to keep it. Consider it a bonus.

Collapse
 
grahamthedev profile image
GrahamTheDev

I have added the following paragraph to section 7 to clarify this part as it was not well written:

"So you should now have 3 buttons, "next", "complete the run" and "reset" plus a checkbox with the label "Reverse order". If "Reverse Order" is checked then pressing "Next" will decrease the number by one and pressing "complete the run" will count downwards from the current number. "

Collapse
 
afif profile image
Temani Afif

My CSS only solution. Work from 1 to infinity (chrome and edge only)

codepen.io/t_afif/pen/dyWpree

Will probably optimize later to cover more cases.

Collapse
 
grahamthedev profile image
GrahamTheDev • Edited

I knew I could count on you to use CSS to solve JS problems!

Looking at it it is more difficult than I thought to do with CSS.

I thought a :before and :after combo was going to be the trick but didn't actually think about how to fix positioning like that!

Really interesting solution! ❤

Collapse
 
grahamthedev profile image
GrahamTheDev • Edited

I hope the instruction are clear and this is a fun Sunday challenge for people.

My answer will come out next week / the best answers for both beginner and pro.

Oh and if you are one of those people who really like to show off - you can code golf your answer if you want (but still in JavaScript please)!

I look forward to seeing what people submit (if anyone does that is!)!

oh and please ensure it is a runnable sandbox fiddle / pen etc. so people can play with your entry!

Collapse
 
siddharthshyniben profile image
Siddharth

Mistake – You mention a direction in the table in step 5, but there's no decrease button!

Collapse
 
grahamthedev profile image
GrahamTheDev • Edited

Ah now I get you, I changed the order of challenges and forgot about that part. I think I have now accounted for that, great spot!

Thanks for pointing it out! ❤

Collapse
 
nmalyschkin profile image
Nikita Malyschkin • Edited

Wow, great challenge! This inspired me to make a small extra challenge:

Classic fizzbuzz, but:

  • "use strict"
  • no eval or such (obviously)
  • does not expose signature to user (e.g. when using recursion)
  • no let/var
  • no modulo operator (%) and no Math Object
  • no loops
  • can run beyond ~30.000
  • no if/else
  • no const
  • no compare operations (==, ===, !=, !==)
  • no return statements
  • no curly brackets {} 😈

It's solvable, have fun :D

Collapse
 
grahamthedev profile image
GrahamTheDev • Edited

That sounds horrific! If I get chance I will see if I can put a solution together but as the England vs Italy match is on at the moment it will have to wait! 😋

Collapse
 
virejdasani profile image
Virej Dasani

Check out FizzBuzz-Everything, a community driven GitHub repo with FizzBuzz written in a whole lotta languages!

Collapse
 
grahamthedev profile image
GrahamTheDev

Thats really cool, I will include it in the part 2 / follow up piece if I remember. Thanks for sharing!

Collapse
 
grahamthedev profile image
GrahamTheDev

Looks good, I will have a run through it soon!