How can I make my prefab fire out at a random velocity every 2 secs

Hi guys, I’m a novice when it comes to writing scripts in any language. What I’m trying to do is fire a prefab I made (cannonball) out of a cannon every 2 seconds at a random velocity each time it fires. The cannon is supposed to fire once the scene loads. When the prohectile is fired it is going to hit a target and when it does, it is supposed to be teleported to the right side of the screen to be collected. Hope that wasn’t too confusing. What I need help with is the random velocity every 2 seconds and when the projectile hits the target and gets transported. Here is my code thus far. To test if things worked I made it so the ball with the left mouse button. I want this changed obviously to the constant, every 2 seconds when the scene loads.
#pragma strict

//Attach to empty object, in front of barrel
 
var projectile : Rigidbody; //The Bullet
 
var speed = 250; //Speed Of The Bullets
 
var fireRate = .5;//Time Delay Between Shots!
 
 
function Update()
 
{
 
        InvokeRepeating("Fire",fireRate,0.3); //Shoot Delay
 
}
 
 
 
//function Fire()
 
{
 
    if(Input.GetMouseButtonDown(0))
    {
	    //audio.Play();
	 var gunShot : AudioClip;
	 var instantiatedProjectile : Rigidbody = Instantiate(projectile, transform.position, transform.rotation );
	 
	 
	        instantiatedProjectile.velocity = transform.TransformDirection( Vector3( 0, 0, speed ) );
	 
	        
	 		
	 		audio.PlayOneShot(gunShot);
	        CancelInvoke();
	 
    }
 
}
@script RequireComponent(AudioSource)

Its probably something very little I have to do, knowing my luck. I just can’t see it. Once again, I’m a noob at this stuff. I understand the code, but to put what I want to do into code is another thing. I’m scripting in JavaScript, I’m just starting to learn C#. Thanks a bunch!

function FireRepeating() {
while(/condition/) {
var bullet = Instantiate(prefab, /position/, /rotation/);
bullet.velocity = /whatever you want/;
yield WaitForSeconds(2);
}
}

Then you can call it by using:

StartCoroutine(FireRepeating());

Try this code. If you need help reading it let me know I’ll help you out.

 var projectile : Rigidbody; //The Bullet
    var fireRate : float = .5;//Time Delay Between Shots!
    var shootTime: float = 0.3;
    //RandomizedShotSpeed//
    var switchSpeed : float = 2.0;
    var currentSpeed : float = 100;

function Update() 
{
	var speed = Array(50,100,150,200,250);
		
	if(Time.time >= switchSpeed )
	{
		var index = Random.Range(0, speed.length);
		switchSpeed += 2.0;
		currentSpeed = speed[index];
    	print(currentSpeed);
    }
    
	if(Time.time >= shootTime)
	{
    	var instantiatedProjectile : Rigidbody = Instantiate(projectile, transform.position, transform.rotation );
      	instantiatedProjectile.velocity = transform.TransformDirection( Vector3( 0, 0, currentSpeed ) );
    	shootTime += fireRate;		
	}	
}