r/learnjavascript • • Jan 25 '26

Help with reading file via JavaScript

1 Upvotes

I have a project that I’ve been tweaking that is used only on local lan. I have a html that uses a JavaScript file that queries functions from a python file. I also have a saved_variables.cfg file on same server that has the following line:

ace_inventory = [{'status': 'ready', 'color': [255, 0, 0], 'material': 'PLA', 'temp': 220}, {'status': 'ready', 'color': [0, 255, 0], 'material': 'PLA', 'temp': 220}, {'status': 'ready', 'color': [255, 255, 255], 'material': 'PLA', 'temp': 220}, {'status': 'ready', 'color': [0, 0, 0], 'material': 'PETG', 'temp': 250}]

I want to be able to read that file and pull the rgb colors to use in the html page so it shows the correct color in a box.

What is the best way to do this given the file is in the same folder as the html and JavaScript files?

Thanks


r/learnjavascript • • Jan 25 '26

Dev Blink - Request Error Monitor for your LOCALHOST developments

0 Upvotes

r/learnjavascript • • Jan 25 '26

This reduce function is overcounting and I don't know why

3 Upvotes

I am working in visual studio code and I am very new to javascript.

In this part of my assignment I must write my own reducer function then use that reducer function to find out how many small, medium, and large transactions there are. A transaction is a dictionary of information, one of which is "amount". The transactions variable is an array of these dictionaries.

here is the code:

let smallTransactions = reduce(transactions, (value, count) => {
        if(value["amount"] < 25) count += 1; return count;}, 0);
    let mediumTransactions = reduce(transactions, (value, count) => {
        if(value["amount"] >= 25 && value["amount"] < 75) count += 1; return count;}, 0);
    let largeTransactions = reduce(transactions, (value, count) => {
        if(value["amount"] >= 75) count += 1; return count;}, 0);


    console.log("Small: " + smallTransactions);
    console.log("Medium: " + mediumTransactions);
    console.log("Large: " + largeTransactions);

and the reduce function:

function reduce(data, reducer, initialValue) {
    let product = initialValue;
    
    for (let element of data) {
        product = reducer(element, product);
    }
    return product;
}

It is supposed to return this:

Number of small transactions: 1150
Number of medium transactions: 2322
Number of large transactions: 8315

but instead its returning this:

Number of small transactions: 1425
Number of medium transactions: 2404
Number of large transactions: 8594

Any idea why its doing that? I can't figure it out.


r/learnjavascript • • Jan 24 '26

Made this directory of zero-build JS tools for simplicity

5 Upvotes

Hi r/learnjavascript  !

I'm working on this directory that compiles around 50 lightweight JS tools that requires absolutely no npm installs and no build steps, allowing for a streamlined dev experience, just a simple script tag and start coding! Would really like some feedback on my selection of the tools and engines or any tools you would like added to the website!

I thought these simple tools and setup processes would make it easier for beginner devs and everyone else alike to learn JS easier and experiment without needing to type in "npm install" ever again (i am being a bit overdramatic here with the repeated mentions of npm install, yes, but...)

Thank you all so much! :)

The website: https://vietnamesecoder.github.io/nobuild/


r/learnjavascript • • Jan 24 '26

Simple Data Input Javascript program

0 Upvotes

I want to ask a user to input their first name, and the state were they live. Then send to a database. I am a NEWBIE. Help. Note: I did download node.js. I really don't know what I'm doing yet. Looks for a simple program to do this on my laptop. Any help appreciated.


r/learnjavascript • • Jan 24 '26

question about using ES6 classes.

1 Upvotes

pastebin

i was wondering, would this code be syntactically OK? i imagine there might be scenarios where you want all the functionality of the superclass method, but then you simply want to add more statements (more implementation) to it... could this work?


r/learnjavascript • • Jan 24 '26

Why can’t I see what’s in the multidimensional array?

1 Upvotes

This is my first time actually coding in javascript but I have experience in python and java. I am using Visual Studio Code and it is my first time using it.

I coded this very basic reduce function. The way I call this function results in a series of arrays. Everything other than the reduce function itself is provided to me by my teacher so I would perfer not to change it.

Here is the code:

const nums = [1,2,3,4,5];

const evensAndOdds = reduce(nums, (value, acc) => { if (value % 2 == 0) { acc.evens.push(value); } else { acc.odds.push(value); } return acc; }, {evens: [], odds: []});

console.log(evensAndOdds);

function reduce(data1, reducer, initialValue) { let reducedProduct = 0;

for (let element of data1) {
    let product = reducer(element, initialValue);
    reducedProduct += product;
}
return reducedProduct;

}

========================================================================== And here is the output:

0[object Object][object Object][object Object][object Object][object Object]

========================================================================= I want to be able to see the actual values. The example provided to me by my teacher says the result should be //{evens: [2,4], odds: [1,3,5]}; I understand my code could be wrong but I wont really know unless I can see the actual values.