Hi all,
I need help importing a javascript variable from one big javascript file to a script file inside an html document.
See the code snippet below:
if(total === 1)
{
let probabilty = 1/2;
let initialAmount = document.querySelector(".user-inputs").value;
let midLevelAmount = (0.98 - probabilty)/probabilty
let finalAmount = midLevelAmount* initialAmount;
The code above is part of a large independent JavaScript file called ‘one-in-two-functions.js’ . Now, I want to use the ‘finalAmount’ variable in a script js file which is inside an html document.
See the code below:
</div>
</div>
</body>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script src="/js/one_in_two_functions.js"></script>
<script src="/js/one_in_two.js" ></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
// I want to use the finalAmount variable in the below script file
<script>
function handleBalance() {
console.log('working!!!!!!!!')
const url =
//'https://lotto-beta.herokuapp.com/api/games'
`http://localhost:3000/api/games`
const data = {
amount: document.querySelector('.user-inputs').value
}
document.getElementById("checker").innerHTML = "Checking"
const res = axios.post(url, data).then(resp => {
console.log('data sent')
document.getElementById("checker").innerHTML = "Check"
setTimeout(function(){ window.location.reload(); }, 2000);
}).catch(err => {
console.log(err);
});
}
</script>
</html>
I want to use the ‘finalAmount’ variable from ‘one-in-two-functions.js’ , inside the last script tag in the html file, specifically inside the ‘handleBalance’ function.
I’m wondering how I can do that successfully. I’ve been getting errors.
Please help.