r/learnjavascript • • Jan 25 '26

Feedback/Proofreading Needed

1 Upvotes

Starting a JavaScript college course and already having issues, our first assignment is as follows:

Add an onclick event handler to the <input> tag that changes the innerHTML value of the page element with the id “submitMsg” to the text message Thank you for your order.

It's supposed to display a message after pressing the Submit button, so I figured I'd only need to modify the one <input> line but I'm getting no results (no message is displaying). Here's the code segment so far:

HTML;

<fieldset id="submitbutton">
          <input type="submit" value="Submit" onclick="document.getElementById('submitMsg').innerHTML = 'Thank you for your order.'" />
</fieldset>

CSS;

#submitbutton {
  border: none;
  background: #93AD78;
  padding: 0.5em 0;
  margin-bottom: 0;
  text-align: center;
  }
  
  div#submitMsg {
     height: 30px;
     color: red;
     line-height: 30px;
     font-size: 20px;
  }

Does anyone know where I'm going wrong?


r/learnjavascript • • Jan 25 '26

Make minesweeper clone as my first JS project.

7 Upvotes

A lot harder than I thought. Any feedback is appreciated.

Github Link: Click here

Live Demo: Click here

Art Credit: Thanks Kia for free art asset 🙏


r/learnjavascript • • Jan 25 '26

I'm having a hard time building up logic in JavaScript functions, do you guys have any tips?

10 Upvotes

I am a beginner in JavaScript and I can understand normal and higher order functions but applying them seems really challenging, I was wondering if you guys have any tips that I can use to improve, and if there are any sureshot ways to build really strong logic.

Any advice is highly appreciated!


r/learnjavascript • • Jan 25 '26

JavaScript show/hide code not displaying correctly

0 Upvotes

I have code to hide/show an image in a table. My table has 6 columns, with data in the first row across all 6 columns. In the next row, I have the image. When I load the page, I hide the image row by default. Originally, I had the image centered across all 6 columns, but when I click an image to show the row, the image shows only in the first column. I then forced the image to be in the 3rd column. In this scenario, the same thing happens. If I do not hide the row, the image shows as expected in the 3rd column. If I then hide the row, and open it again, the image displays in the 1st column.

Here is a snippet of my code ::

Javascript ::

function ReverseDisplayTbody(d) {

`if(document.getElementById(d).style.display == "none") {`

	`document.getElementById(d).style.display = "block";`

	`document.getElementById('img'+d).setAttribute('src', "images/minus.gif");`

`}`

`else {`

	`document.getElementById(d).style.display = "none";`

	`document.getElementById('img'+d).setAttribute('src', "images/plus.gif");`

`}`

}

HTML/PHP ::

<tr>

`<td><a href='javascript:ReverseDisplayTbody($thisSetID)'><img src='images/plus.gif' id=img$thisID kborder='0'></a></td>`

`<td class='txt'><a href='mylink.com' target ='_blank'>$thisID</a></td>`

`<td class='txt'>$thisSetName</td>`

`<td class='txt'>$thisSetType</td>`

`<td class='txt center'>$thisNbrBlks</td>`

`<td class='txt center'>$thisOwner</td>`

</tr>

<tr id='$thisID'>

`<td>\&nbsp;</td>`

`<td>\&nbsp;</td>`

`<td><img src='https://mylink.com/sets/$thisID-1.jpg'></a></td> <!-- Image -->`

`<td>\&nbsp;</td>`

`<td>\&nbsp;</td>`

`<td>\&nbsp;</td>`

</tr>


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.