Functions

JS4Scratch Reference Manual:

Non-Returning Functions

Syntax:

function yourFunctionName(){
    // your code
}

Example:

function myFunction(){
    console.log("myFunction just ran")
    spriteA.move(50)
}

spriteA.whenFlag(function () {
    this.show()
    this.say('press the space bar to run function that moves this sprite')
    this.whenKeyPressed(' ', function() {
        myFunction()
    })
})

Returning Functions

Syntax:

function yourFunctionName(input1,input2) {
    return input1 (your maths) input2
}

Example:

function anotherFunction(p1,p2){
    return p1 + p1
}
console.log(anotherFunction(5,5))