Exercism v3 launches on Sept 1st 2021. Learn more! ๐Ÿš€๐Ÿš€๐Ÿš€
Avatar of Nnouka

Nnouka's solution

to Raindrops in the JavaScript Track

Published at May 22 2021 · 0 comments
Test suite

Your task is to convert a number into a string that contains raindrop sounds corresponding to certain potential factors. A factor is a number that evenly divides into another number, leaving no remainder. The simplest way to test if a one number is a factor of another is to use the modulo operation.

The rules of raindrops are that if a given number:

  • has 3 as a factor, add 'Pling' to the result.
  • has 5 as a factor, add 'Plang' to the result.
  • has 7 as a factor, add 'Plong' to the result.
  • does not have any of 3, 5, or 7 as a factor, the result should be the digits of the number.


  • 28 has 7 as a factor, but not 3 or 5, so the result would be "Plong".
  • 30 has both 3 and 5 as factors, but not 7, so the result would be "PlingPlang".
  • 34 is not factored by 3, 5, or 7, so the result would be "34".


Go through the setup instructions for Javascript to install the necessary dependencies:



Please cd into exercise directory before running all below commands.

Install assignment dependencies:

$ npm install

Making the test suite pass

Execute the tests with:

$ npm test

In the test suites all tests but the first have been skipped.

Once you get a test passing, you can enable the next one by changing xtest to test.

Submitting Solutions

Once you have a solution ready, you can submit it using:

exercism submit raindrops.js

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

Exercise Source Credits

A variation on FizzBuzz, a famous technical interview question that is intended to weed out potential candidates. That question is itself derived from Fizz Buzz, a popular children's game for teaching division. https://en.wikipedia.org/wiki/Fizz_buzz


import { convert } from './raindrops';

describe('Raindrops', () => {
  test('the sound for 1 is 1', () => expect(convert(1)).toEqual('1'));

  xtest('the sound for 3 is Pling', () => expect(convert(3)).toEqual('Pling'));

  xtest('the sound for 5 is Plang', () => expect(convert(5)).toEqual('Plang'));

  xtest('the sound for 7 is Plong', () => expect(convert(7)).toEqual('Plong'));

  xtest('the sound for 6 is Pling as it has a factor 3', () =>

  xtest('2 to the power 3 does not make a raindrop sound as 3 is the exponent not the base', () =>

  xtest('the sound for 9 is Pling as it has a factor 3', () =>

  xtest('the sound for 10 is Plang as it has a factor 5', () =>

  xtest('the sound for 14 is Plong as it has a factor of 7', () =>

  xtest('the sound for 15 is PlingPlang as it has factors 3 and 5', () =>

  xtest('the sound for 21 is PlingPlong as it has factors 3 and 7', () =>

  xtest('the sound for 25 is Plang as it has a factor 5', () =>

  xtest('the sound for 27 is Pling as it has a factor 3', () =>

  xtest('the sound for 35 is PlangPlong as it has factors 5 and 7', () =>

  xtest('the sound for 49 is Plong as it has a factor 7', () =>

  xtest('the sound for 52 is 52', () => expect(convert(52)).toEqual('52'));

  xtest('the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7', () =>

  xtest('the sound for 3125 is Plang as it has a factor 5', () =>
// This is only a SKELETON file for the 'Raindrops' exercise. It's been provided as a
// convenience to get you started writing code faster.

export const convert = (rain) => {
  let sound = "";
  if(rain % 3 === 0) {
    sound += 'Pling';
  if(rain % 5 === 0) {
     sound += 'Plang';
  if(rain % 7 === 0) {
     sound += 'Plong';
  if(sound == "") {
    sound = String(rain);
  return sound;

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other peopleโ€™s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?