Collision Syntax for Basic Jumping

https://playcanvas.com/project/517897/overview/my-first-game

This is the only script in my project. I want the player to be able to jump when on the ground but not when in the air. Sorry my code is so ugly, I’m still a beginner.

var ApplyForce = pc.createScript(‘applyForce’);

ApplyForce.attributes.add(‘speed’, {
type: ‘number’,
default: 1
});
ApplyForce.attributes.add(‘jump’, {
type: ‘number’,
default: 5
});
ApplyForce.attributes.add(“Ground”, {
type: ‘entity’
});

// initialize code called once per entity
ApplyForce.prototype.initialize = function() {
this.entity.collision.on(“collisionstart”, this.onCollisionStart, this);
this.entity.collision.on(“collisionend”, this.onCollisionEnd, this);
};

var onGround = true;

// update code called every frame
ApplyForce.prototype.update = function(dt) {
if (this.app.keyboard.wasPressed(pc.KEY_RIGHT)) {
this.entity.rigidbody.applyImpulse(this.speed,0,0);
}
if (this.app.keyboard.wasPressed(pc.KEY_LEFT)) {
this.entity.rigidbody.applyImpulse(-1this.speed,0,0);
}
if (this.app.keyboard.wasPressed(pc.KEY_UP)) {
this.entity.rigidbody.applyImpulse(0,0,-1
this.speed);
}
if (this.app.keyboard.wasPressed(pc.KEY_DOWN)) {
this.entity.rigidbody.applyImpulse(0,0,this.speed);
}
if (this.app.keyboard.wasPressed(pc.KEY_D) && onGround === true) {
this.entity.rigidbody.applyImpulse(0,this.jump,0);
}

ApplyForce.prototype.onCollisionStart = function(result) {

if (result.other == this.ground) {
    onGround = true;
}

};

ApplyForce.prototype.onCollisionEnd = function(result) {

if (result.other == this.ground) {
    onGround = false;
}

};

};