If input is number - returns it,
else returns zero.
const returnInputNumber = (n = 0) => { return typeof n === "number" ? n : 0; };
const returnInputNumber = n => n- const returnInputNumber = (n = 0) => {
- return typeof n === "number" ? n : 0;
- };
const assert = require("chai").assert; describe("Getter", () => { it("sample", () => { assert.strictEqual(returnInputNumber(-4), -4); assert.strictEqual(returnInputNumber(0), 0); assert.strictEqual(returnInputNumber(1), 1); assert.strictEqual(returnInputNumber(2), 2); assert.strictEqual(returnInputNumber(), 0); assert.strictEqual(returnInputNumber("Mistake"), 0); }); });
- const assert = require("chai").assert;
- describe("Getter", () => {
- it("sample", () => {
- assert.strictEqual(returnInputNumber(-4), -4);
- assert.strictEqual(returnInputNumber(0), 0);
- assert.strictEqual(returnInputNumber(1), 1);
- assert.strictEqual(returnInputNumber(2), 2);
- assert.strictEqual(returnInputNumber(), 0);
- assert.strictEqual(returnInputNumber("Mistake"), 0);
- });
- });
const helloWorld = (name) => `Hello, ${name}.`;
const helloWorld = n => ('Hello ' + n)- const helloWorld = (name) => `Hello, ${name}.`;
// Since Node 10, we're using Mocha. // You can use `chai` for assertions. const chai = require("chai"); const assert = chai.assert; // Uncomment the following line to disable truncating failure messages for deep equals, do: // chai.config.truncateThreshold = 0; // Since Node 12, we no longer include assertions from our deprecated custom test framework by default. // Uncomment the following to use the old assertions: // const Test = require("@codewars/test-compat"); describe("Solution", function() { it("Test for name assertion and greet diplaying", function() { //Test.assertEquals(helloWorld("Anna"), "Hello Anna"); assert.strictEqual(helloWorld("Anna"), "Hello, Anna."); assert.strictEqual(helloWorld("Luuk"), "Hello, Luuk."); }); });
- // Since Node 10, we're using Mocha.
- // You can use `chai` for assertions.
- const chai = require("chai");
- const assert = chai.assert;
- // Uncomment the following line to disable truncating failure messages for deep equals, do:
- // chai.config.truncateThreshold = 0;
- // Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
- // Uncomment the following to use the old assertions:
- // const Test = require("@codewars/test-compat");
- describe("Solution", function() {
it("should test for something", function() {- it("Test for name assertion and greet diplaying", function() {
- //Test.assertEquals(helloWorld("Anna"), "Hello Anna");
assert.strictEqual(helloWorld("Anna"), "Hello Anna");- assert.strictEqual(helloWorld("Anna"), "Hello, Anna.");
- assert.strictEqual(helloWorld("Luuk"), "Hello, Luuk.");
- });
- });