Use data from variable in another function

I’ve got a function like this (value is from select):

function getSelectValuePower () {
 var power = document.getElementById("power").value;
  sessionStorage.setItem("power", power);
  console.log(power);
}

How can I use value from variable power in another function ?
For example :

I want to use it here :

function getValue () {
  var number = 10;
  var selectedValue = number + power;
  console.log(selectedValue2);
}

So, when my power is 7, the result in getValue() should be 17.

I tried to do it with global variables, but doesn’t work.

>Solution :

Get power in second function:

var power = sessionStorage.getItem("power");

Leave a Reply