From 6cf3662f55aeedac59883be763b602d5a3a5cdc4 Mon Sep 17 00:00:00 2001 From: Mohammed Nabeel Date: Thu, 2 Jul 2020 09:41:16 +0300 Subject: [PATCH] passed returns ERROR with negative numbers --- repeatString/repeatString.js | 4 ++++ repeatString/repeatString.spec.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/repeatString/repeatString.js b/repeatString/repeatString.js index 62df807..b66ff26 100644 --- a/repeatString/repeatString.js +++ b/repeatString/repeatString.js @@ -2,6 +2,10 @@ const repeatString = function(sourceString, stringCount) { //Declare variable/s let resultString = ''; + //Return error if stringCounter is negative + if (stringCount < 0) { + return 'ERROR'; + } // Create a for loop to repeat the string for (let i = 0; i < stringCount; i++) { diff --git a/repeatString/repeatString.spec.js b/repeatString/repeatString.spec.js index 20bff3f..d7fa59b 100644 --- a/repeatString/repeatString.spec.js +++ b/repeatString/repeatString.spec.js @@ -13,7 +13,7 @@ describe('repeatString', function() { it('repeats the string 0 times', function() { expect(repeatString('hey', 0)).toEqual(''); }); - xit('returns ERROR with negative numbers', function() { + it('returns ERROR with negative numbers', function() { expect(repeatString('hey', -1)).toEqual('ERROR'); }); xit('repeats the string a random amount of times', function() {