Giter Site home page Giter Site logo

02-fizzbuzz-lab's Introduction

FizzBuzz

Objectives

  1. Build methods that utilize flow control
  2. Read and understand test output to develop a working program
  3. Gain more familiarity with the concept of test driven development

Test Driving FizzBuzz

A classic programming problem is FizzBuzz. It is considered the "Stairway to Heaven" of programming because there are so many different ways to play it and everyone plays it.

The goal of FizzBuzz is to build a program that can take a number and if the number is evenly divisible by 3, it should return "Fizz", if it's divisible by 5, it should return "Buzz", and if it's divisible by both 3 and 5, it should return "FizzBuzz".

Defining Our Expectations

Let's approach solving this problem from a TDD approach. That means what we don't care about "how", but rather, we care about "what". What should the program do if it works correctly, not how it does it. In plain english, the here's what the RSpec tests expect:

  1. We expect fizzbuzz(3) to return "Fizz"
  2. We expect fizzbuzz(5) to return "Buzz"
  3. We expect fizzbuzz(15) to return "FizzBuzz"

Furthermore, we could also provide a negative case.

  1. We expect fizzbuzz(4) to return nil or nothing or ""

We don't care how that #fizzbuzz method works, nor how it's defined, we are just stating our expectations. And we're doing that first. When coding, it's important to have a target to shoot for; by writing your test first and stating your expectations of your code, you know your goal. You get to use your entire brain to think about just your goals, not how you'll get there, which adds clarity and focus to the problem.

Test-Driven Development allows us to fully utilize our mental capacity to clearly state the problem we're solving and then to 100% focus on implementing a solution. When you are just coding, you're actually focusing on stating the problem and the solution at the same time. You are thereby splitting your thinking in two, making you less effective at both.

It's the exact same reason you make a todo list. Also testing is not for present you, it's for future you.

โ€” Joe M Burgess

Good luck!

Code your solution in fizzbuzz.rb.

Use rspec to guide you through solving this lab.

HINT: one math operator you might need for this lab is modulus (%) or "mod". In short, it returns the remainder of the left operand divided by the right operand.
Read more about mod here.

02-fizzbuzz-lab's People

Contributors

annjohn avatar kthffmn avatar msuzoagu avatar aviflombaum avatar bmuellerhstat avatar codebyline avatar deniznida avatar loganhasson avatar roseweixel avatar ahimmelstoss avatar changamanda avatar davidnoahball avatar dandanberry avatar sarogers avatar sammarcus avatar pletcher avatar fs-lms-test-bot avatar arelenglish avatar drewprice avatar mike-xie avatar mrmitchboyer avatar preetness avatar sophiedebenedetto avatar octosteve avatar fislabstest avatar fabiov4177 avatar gj avatar jonbf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.