rigidbody2D only jump while grounded

Hello I am a new user to Unity and I am currently using JavaScript. Right now i have a question on how to make it that my rigid body can only jump while being grounded. Right now you can press W over and over and go flying up into the sky. I am using the code

#pragma strict

var jumpSpeed: float = 10;

function Start () {

} function Update () { if
(Input.GetKeyDown (KeyCode.W)){

rigidbody2D.velocity.y = jumpSpeed;
} 

}

Any help would be greatly appreciated!
The ground i am using is completely flat!

If you want the character to move and jump on inputs, you can use CharacterController.

Following commented code is right for you.

var groundCheck : Transform;
var b_grounded : bool = false;
function Start ()
{
   groundCheck = transform.Find("groundCheck");
}
 
// Update is called once per frame
function Update () {
b_grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground"));
 
print(b_grounded);
}
}