I'm a begginer using a Cloud9 environment that runs in js.
I have an assignement in which I need to use a global variable that will be modified every time a function is called. To my knowledge I have to use a global since I need to store the current value of the variable to be able to change it everytime the function is called.
At first I got a warning message saying:
VarName is not defined, please fix or add /*global VarName*/
Which I fixed by adding what is said there.
Now I get this warning:
Read-only global VarName should not be modified.
I've been stuck with this for a long time and could really use an advice on how to solve this.
These are the lines of the code involved in what I say:
/*global distance*/
let distance=0;
// Function that returns the total distance traveled
function distanceTraveled(speed){
distance=distance+speed*(1/6);
return distance;
}
function distanceToTarget(totalDistance){
totalDistance=totalDistance-distanceTraveled(0);
return totalDistance;
}
Note: I've been only using js for some days and have little coding experience.