Controlling animation speed

Greetings! I’ve got such a question:

I want to control my animation movement speed by pressing a key on a keyboard.
For example, when the specified key is held, animation plays (play speed 1.0), but when I release the key it should stop (play speed 0.0). And when I will press the key again it continues from the point where it was stopped.

I’m trying to deal with it in this way:

function Update (){
      if(Input.GetKey("page up"))
      animation.Play("animation_name");
      animation["animation_name"].speed= 1.0;      
      else
      animation["animation_name"].speed = 0.0;
      }

It doesn’t work, saying: BCE0044: expecting }, found 'else and something like that. I know that I do it wrong, but don’t know how will be correct.
I wish if only you could help me with this task. Just some advices.
PS: I have read practically every topic concerning this question, but still don’t understand.

The error is because you have more than one command in your if statement, but didn’t open / close the if statement with brackets. Go from there. Also check to see if your animation is already playing or not before you play it, so it doesn’t start over each time.

#pragma strict

function Update ()
{
	if(Input.GetKey("page up"))
	{
		if(!animation.isPlaying)
			animation.Play("animation_name");
		
		//This isn't part of your if(!animation.isPlaying) condition.
		animation["animation_name"].speed= 1.0;
	}
	
	else
		animation["animation_name"].speed = 0.0;
}

you’re missing the bracket before and after the ‘if’ statement begins and ends. You have to end the ‘if’ statement before you start the ‘else’ statement. It should be this:

function Update (){
       if(Input.GetKey("page up")) {
       animation.Play("animation_name");
       animation["animation_name"].speed= 1.0; 
       }     
       else {
       animation["animation_name"].speed = 0.0;
     }
 }