I feel a bit silly, there is probably a real easy solution but I've spend days and I still can't find it.
All I'm looking to do is have a script filled with masses of (var a) and the user enters a number into an input (not a promt). then every (var a) becomes that number.
a = (userinput)
b = (userinput)
a+a+a+a = (output)
a+a+a+b = (output)
a+a+b+b = (output)
a+b+b+b = (output)
b+b+b+b = (output)
a*a+b*b =...
etc...
I have done the following Brad Travesty crash courses: JavaScript, Node.js, AJAX, JSON, Fetch API. I've also looked a bit into localStorage.
Please help, 20 hours in the past 2 days with no progress and I'm going a little... 😵😬😖🥴
Thanks,
Jack
---(edit)---
I was thinking I'd have to have (var a) stored on a separate file then user inputs would update that file and all (var a) values would change.
The same problem has come up a few times though: I run a function to retrieve the value but then I'm unable use that data outside of the function. i.e.
document.getElementById('btn').addEventListener
('click', loadText);
function loadText(){
var xhr = new XMLHttpRequest();
xhr.open('GET', 'value.txt', true);
xhr.onprogress = function(){
}
xhr.onload = function(){
if(this.status = 200){
document.getElementById('text').innerHTML = this.responseText;
}
}
xhr.send();
}
Please note: I'm not necessary trying to get the above code to work. This is simply one method I tried. It also may be an inefficient method.
I think my question is "What should I do?" as well as "How do I do it?"
---- The end goal is consists of this in 64 variations.
function colourabc(){
var myNodeList = document.querySelectorAll('.abc');var i;
for (i = 0; i < myNodeList.length; i++)
{myNodeList[i].style.backgroundColor
= 'rgb(' + a + ',' + b + ',' + c + ')';
}}
This set of 64 is to be repeated at least 4 more times.
I want 4 boxes at the top of the page that people write the values of a, b, c and d into.
Thanks again