Counting Sheep Recursivly Test Error


#1

I'd like to mention the Counting Sheep Recursivel allows for the user to pass the exercise by calling the countSheepWithLoop() .

Below is a reference to what I am talking about:

 // Here is the function using a for loop
function countSheepWithLoop(number) {    
  for (i = 1; i <= number; i++) {
    if (i === number) {
      console.log("Zzzzzz");
    }
    console.log("Another sheep jumps over the fence.");
  }
}

// And here is the recursive function
function countSheep(number) {
  if (number === 0) {
    return console.log("Zzzzzz");     
    } else {
	console.log("Another sheep jumps over the fence.");
	// Define the variable newNumber as 
	// 1 less than the input variable number
	newNumber = number - 1; 
	// Recursively call the function
	// with newNumber as the parameter
	countSheep(newNumber);
  }
}
countSheepWithLoop(12);  // This passes

I also could not find a confirmed category but I attempted to find the most appropriate spot for it.

Here the problem link:
https://www.codecademy.com/courses/javascript-lesson-205/2/2


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.