repl.it
@anonymous/

AlertRaggedDrawing

Nodejs

No description

fork
loading
Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"use strict";

/**
 * Ninja secret call sound function
 * 
 * @param {number} count The number of times the word "chirp" should be repeated
 * @throws If the argument count is not valid
 * @throws If the first argument is not a number
 * @throws If the first argument is not greater than 0
 * @return {string} The ninja secret call sound
 * @example chirp(15);
 */
function chirp(count) {
    if (arguments.length !== 1) {
        throw new Error("Expected exactly one parameter.");
    }

    if (typeof count !== "number") {
        throw new TypeError("First argument expected to be a number.");
    }

    if (count <= 0) {
        throw new Error("First argument expected to be greater or equal to 1.");
    }

    if (count === 1) {
        return "chirp.";
    }

    const decreasedCount = count - 1;

    return `chirp-${chirp(decreasedCount)}`;
}

console.log(chirp(4));
console.log(chirp(3));
console.log(chirp(2));
console.log(chirp(1));
console.log(chirp(0));