Instructions:
If you can't sleep, just count sheeps!!
Task:
Given a non-negative integer, 3 for example, return a string with a murmur: "1 sheep...2 sheep...3 sheep...". Input will always be valid, i.e. no negative integers.
Thoughts:
1.I define a variable murmur outside of the for loop, to be able to use it after the loop block.
- I define a for loop as I do not know the num parameter. Inside the for loop, I add to the murmur variable the number i and the string sheep... . This addition is keep happening until the number i will be equal with number num.
Solution:
var countSheep = function (num){
let murmur = '';
for(let i= 1; i <= num; i++){
murmur += i + ' sheep...'
}
return murmur;
}
This is a CodeWars Challenge of 8kyu Rank (https://www.codewars.com/kata/5b077ebdaf15be5c7f000077/train/javascript)