How can move an object alternatively up and down using just one tap action.

How can move an object alternatively up and down using just one tap action.
I’m trying to make a one tap game which involves only vertical movements .
I am new to unity and following is my code but it dosnt works perfectly:-
I’m calling the function movement from a buttons on click property

public class sphere : MonoBehaviour
{

public float speed;
Vector3 velocity;
public Rigidbody rb;
int i;

void Start()
{
    rb = GetComponent<Rigidbody>();
     i = -1;
    velocity = new Vector3(0, speed, 0);
}

public void movement()
{
    if (i>0)
    {
 
        rb.velocity = new Vector3(0, speed, 0);
        i = -1;
    }
    else
    {

        rb.velocity = new Vector3(0, -speed, 0);
        i = 1;

    }
}

}

@decoy109 Maybe try

rb.AddForce(Vector3.up * speed);