JavaScript, how to open file under new folder?

Hi! I’m a newbie here, and I’ve just started learning JS. Can someone help me and explain how to open a file under a new folder in JS?

Hey @cl4767 welcome to the forums!

If you create a folder and a file in your Repl you can drag the file into your folder and it will placed inside. I hope this helps!

1 Like

Hey @SalladShooter thank you for answer. I might have expressed myself incorrectly. I created a new folder and a new file within this folder. However, when I attempt to run the code, the system executes the default script.js file instead of my file hw#1.js within the folder.

I believe I need to inform the system somehow that I want to run my new file instead of the default script.js file when I click the “Run” button. How can I configure it so that the “Run” button executes my file?

@cl4767 you will either have to take your main JS file out of the folder. Or configure it in the .replit file. Click the three dots next to the Files >, click Show Hidden Files, go to the .replit file and change run=“” to your file path. I hope this helps!

1 Like

When you click the run button, it opens your HTML page in an iframe. All you have to do to change what script is run is change your HTML file (index.html).

On line 13, you have:

<script src="script.js"></script>

To run the hw#1.js file, just change the src to the new file path:

<script src="School/hw#1.js"></script>

By the way, looks like you might have Java confused with JavaScript, System.out.println is Java, not JavaScript. The two languages are completely different. (My understanding of the naming of JavaScript is that the name was essentially clickbait trying to make use of the popoularity of Java at the time of its creation.)

You probably want to make a habit of using === rather than == in JavaScript, the details might be a little confusing, but essentially the former is ‘strict’ equals, the latter allows for type coercion.

Additionally, in your alert statement, you alert a string plus two numbers multiplied. While because of operator precedence (the order that operators are ‘run’) this is correct and does work, you may want to put the numbers being multiplied in brackets to help with readbility and also to prevent you from making mistakes in future like adding those two numbers (which will produce some funky results: "abc" + 1 + 2"abc12", not "abc3")


Thank you so much @MattDESTROYER and @SalladShooter

1 Like

Hey @cl4767!

Please mark this post as the solution if it solved your problem so people with the same issue can easily find the solution.

cc: @dragonhunter1 @MattDESTROYER @Firepup650

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.