# thekeele's solution

## to Raindrops in the JavaScript Track

Published at Jul 30 2019 · 0 comments
Instructions
Test suite
Solution

#### Note:

This exercise has changed since this solution was written.

Convert a number to a string, the contents of which depend on the number's factors.

• If the number has 3 as a factor, output 'Pling'.
• If the number has 5 as a factor, output 'Plang'.
• If the number has 7 as a factor, output 'Plong'.
• If the number does not have 3, 5, or 7 as a factor, just pass the number's digits straight through.

## Examples

• 28's factors are 1, 2, 4, 7, 14, 28.
• In raindrop-speak, this would be a simple "Plong".
• 30's factors are 1, 2, 3, 5, 6, 10, 15, 30.
• In raindrop-speak, this would be a "PlingPlang".
• 34 has four factors: 1, 2, 17, and 34.
• In raindrop-speak, this would be "34".

## Setup

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

https://exercism.io/tracks/javascript/installation

## Requirements

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`.

## Source

A variation on a famous interview question intended to weed out potential candidates. http://jumpstartlab.com

## Submitting Incomplete Solutions

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

### raindrops.spec.js

``````import { convert } from './raindrops';

describe('Raindrops', () => {
test('converts 1', () => expect(convert(1)).toEqual('1'));

xtest('converts 3', () => expect(convert(3)).toEqual('Pling'));

xtest('converts 5', () => expect(convert(5)).toEqual('Plang'));

xtest('converts 7', () => expect(convert(7)).toEqual('Plong'));

xtest('converts 6', () => expect(convert(6)).toEqual('Pling'));

xtest('converts 9', () => expect(convert(9)).toEqual('Pling'));

xtest('converts 10', () => expect(convert(10)).toEqual('Plang'));

xtest('converts 14', () => expect(convert(14)).toEqual('Plong'));

xtest('converts 15', () => expect(convert(15)).toEqual('PlingPlang'));

xtest('converts 21', () => expect(convert(21)).toEqual('PlingPlong'));

xtest('converts 25', () => expect(convert(25)).toEqual('Plang'));

xtest('converts 35', () => expect(convert(35)).toEqual('PlangPlong'));

xtest('converts 49', () => expect(convert(49)).toEqual('Plong'));

xtest('converts 52', () => expect(convert(52)).toEqual('52'));

xtest('converts 105', () => expect(convert(105)).toEqual('PlingPlangPlong'));

xtest('converts 12121', () => expect(convert(12121)).toEqual('12121'));
});``````
``````export const convert = (number) => {
let raindrops = '';
let sounds = {3: 'Pling', 5: 'Plang', 7: 'Plong'};

for (const factor in sounds) {
if (number % factor == 0) {
raindrops += sounds[factor];
}
}

return raindrops ? raindrops : `\${number}`;
};``````