Skip to content
Advertisement

Scoping and calling Bitcoin price checker

Hi I’m currently making a Bitcoin Price tracker. I have it rigged up so that it will send me an alert when Bitcoins price hits a certain point. I’m still beginner programmer, but it’s working good so far.

I’m having trouble figuring out how I should scope and then call my two functions without the function calling itself over and over. The variable I need both functions to have access to is ‘current_price’. What is the correct way to scope/organize then call these these so that my inner function can access my outer functions variables? Thank you!

The code:

JavaScript

Advertisement

Answer

There are two ways to do this. Global variables, often frowned upon and passing in current_price as an argument.

Global Variables – frowned upon:

JavaScript

and passing in current price:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement