Program should calculate a number but doesn't. Please help me find the error

javascript

#1

Hello everyone,

In School I was inspired to code a programm which calculates the number of sheep you can have in minecraft after a certain number of days.

Sheep grow up over the Course of a day and two adult sheep can have just one lamb. The sex of the sheep doesn't matter, they're male and female a once. They can't mate again till their lamb has grown up.

Following you see a pic of my code (ignore the comments, I made them for me so they're in german)

Please help me find my mistake.

Here I've got the whole code for you:

var Tage = prompt("Wie viele Tage willst du die Schafe vermehren? (du beginnst mit zwei Schafen)");


var anzahlSchafe = 2;

var Schafe = function(Tage)
{
         for (var i = Tage ; i > 0; i = i-- ); 	
        {
		var ungeradeGerade = anzahlSchafe % 2;

				if ( ungeradeGerade == 0 ); 
		               {
			              var anzahlSchafe = +anzahlSchafe + +(+anzahlSchafe / 2 ); 
				};
		               else 
		               {
			              var anzahlSchafe = +anzahlSchafe + +((+anzahlSchafe - 1 ) / 2 ); 
		
		                };
	};
	return anzahlSchafe;
};
document.write(Schafe(Tage)

#2

Well, here is an improved version of your code:

var Tage = prompt("Wie viele Tage willst du die Schafe vermehren? (du beginnst mit zwei Schafen)");


var anzahlSchafe = 2;

var Schafe = function(Tage)
{
  for (var i = Tage ; i > 0; i = i-- )     
  {
    console.log(i);
    var ungeradeGerade = anzahlSchafe % 2;
    if ( ungeradeGerade == 0 )
    {
      var anzahlSchafe = anzahlSchafe + (anzahlSchafe / 2 ); 
    }
    else 
    {
        anzahlSchafe = anzahlSchafe  +(( anzahlSchafe - 1 ) / 2 ); 
    }
    }
    return anzahlSchafe;
};
document.write(Schafe(Tage));
Schafe(Tage)

where to start? I made a function call, so the function does actually get executed, you had semi-colons where the can be no semi-colons, way to many plus (+) signs, and your loop is a infinity loop, i don't understand why you have the loop in the first place. Tage is one argument, one string or integer (you don't validate userinput), uhm... yea, i believe that was in a very brief overview everything