Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Global variable

ANSWERED

Hi, I have created a clock face and it works well, I am now trying to add a countdown feature, I have all the math and coding issues sorted, but I need to pass a couple of variables through multiple functions, can I create a global variable that will work across multiple functions?

Best Answer
1 BEST ANSWER

Accepted Solutions

Yes, you certainly can.

let globX = 0;

function setX() {
globX = 1; }
function setAnotherX() {
globX = 2; }

Or you can just pass it around the functions.

 

 

function setX() {
  let someX = 1;
someX = setAnotherX(someX) }

function setAnotherX(valX) {
return valX++;
}

 

 

View best answer in original post

Best Answer
0 Votes
3 REPLIES 3

Hello @deaks007 I've moved your post into the app development board.

 

Best Answer

Yes, you certainly can.

let globX = 0;

function setX() {
globX = 1; }
function setAnotherX() {
globX = 2; }

Or you can just pass it around the functions.

 

 

function setX() {
  let someX = 1;
someX = setAnotherX(someX) }

function setAnotherX(valX) {
return valX++;
}

 

 

Best Answer
0 Votes

Yeah I thought it should be like that, been doing the first option and it is not working, I am unsure why. might try a rewrite and see if that fixes my issues.

Thanx.

Best Answer
0 Votes