r/JavaScriptHelp • • Mar 01 '21

❔ Unanswered ❔ How to stop this from happening?

1 Upvotes

Hi, I am very new to Javascript and Node.js. I am trying to take a user input however every time I type a character the question keeps on printing into the console. How do I fix this?

const prompt = require('prompt-sync')();

const name = prompt('What is your name?\n');console.log(`Hey there ${name}`);

This is the output:

What is your name?

What is your name?

What is your name?

What is your name?

kai

Hey there kai


r/JavaScriptHelp • • Mar 19 '21

💡 Advice 💡 Help with coding javascript on code.org applab

1 Upvotes

Hi. I am struggling here haha. I am making an app on code.org to tell the user the number of covid cases in a random state or country. The user can choose whether they want a state or a country. Then whether they want a state/country with a low/medium/high number of cases. When it is run, there is an error:

WARNING: Line: 84: setText() text parameter value (undefined) is not a uistring.ERROR: Line: 84: TypeError: Cannot read property 'toString' of undefined

Any help would be much appreciated thank you.

https://studio.code.org/projects/applab/LtR6Yrqt4qwuMTclvpME_3rl9bjBQ4ml_tB_pW4W6as


r/JavaScriptHelp • • Mar 16 '21

❔ Unanswered ❔ Using particle.js to create a "rolling fog" effect.

1 Upvotes

Hello! I've used basic particle effects in my web designs before, but I have a client that wants a "rolling fog" effect. I think it can be done using particle.js, but I have been struggling hard to make it happen. My first problem is I can't get particle.js to recognize my image file (I've tried SVG & PNG), which is a cloud on a transparent background.

I know there's a trick to it that my novice brain doesn't understand. Can anyone please tell me what I'm supposed to put in the image.src section to bring in my image?

Thank you!


r/JavaScriptHelp • • Dec 23 '20

✔️ answered ✔️ Question about fetch( )

1 Upvotes

I just learned about fetch() and was experimenting with a made-up JSON file when I noticed that a while loop in my code is executing out of place. My JSON file looks like this:

{
  "ZIP_CODE": "12345",
  "CITY": "Helloville",
  "STATE": "OR",
  "COUNTRY": "US",
  "EMAIL": "[email protected]",
  "PHONE": "+12345678901",
  "GENDER": "male"
}

And my JavaScript file looks like this:

const request = new Request('data.json');

fetch(request)
	.then(response => response.json())
	.then(myInfo => {
		
		const b = document.querySelector('body');
		for (const prop in myInfo) {
			let br = document.createElement('br');
			let tn = document.createTextNode(myInfo[prop]);
			
			b.appendChild(tn);
			b.appendChild(br);
		}
		
		let i = 1; // why does this load before the for in loop?
		while (i <= 200) {
			let span = document.createElement('span');
			let br = document.createElement('br');
			let tn = document.createTextNode(myInfo.CITY);
			span.appendChild(tn);
			
			document.getElementById('content').appendChild(span);
			document.getElementById('content').appendChild(br);
			
			i++;
			
		}
		
	});

And finally, the output:

Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville
Helloville

12345
Helloville
OR
US
[email protected]
+ 12345678901
male

My question is, why is the while loop executing before the for loop that precedes it? Thanks in advance.


r/JavaScriptHelp • • Nov 24 '20

✔️ answered ✔️ .toFixed is making my head hurt.

2 Upvotes

Can someone please explains this too me;.

(I am a javascript noob, I mostly code in php)

<html><body>

<button onclick="myFunction()">Try it</button><p id="demo"></p>

<script>function myFunction() {var x = 8.391;var y = x.toFixed(2);var z = y * 76;document.getElementById("demo").innerHTML = z;}</script></body></html>

8.391 rounded to 2 places should be 8.39.

8.39 * 76 = 637.64

The script however outputs 637.6400000000001 ?

I'm trying to fix an issue with an order pages "subtotal" updating and this happens rather than the total being to 2 decile places.


r/JavaScriptHelp • • Nov 30 '20

❔ Unanswered ❔ I am getting node:17200 error when I am trying to place market order using node-binance-api?

1 Upvotes

I am getting mysterious error when I try to place a market order using node-binance-api by using the following function, any suggestion is greatly appreciated!

const Binance = require(’…/node-binance-api’);const binance = new Binance().options({APIKEY: ‘------’,APISECRET: ‘----------’,useServerTime: true

});binance.buy(“BNBUSDT”, 0.3, 0, “MARKET”)

the error I am getting is:(node:17200) UnhandledPromiseRejectionWarning: #(node:17200) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)(node:17200) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


r/JavaScriptHelp • • Dec 15 '20

❔ Unanswered ❔ Trying to check .text content for a word amongst other words

2 Upvotes

So, i apologize for my lack of knowledge. I am cutting snippets and trying to piece together some code, but I have hit a speed bump from time to time so far.

var read = document.getElementById("trophy-picker-6827").textContent

if (read == "eagle") {
  alert(read)
  var eagle = true;

}

The above code has been working for a single word in the ID, but I need it to work by checking that element through multiple words to see if eagle exist in the ID.

The web page is at: https://www.oamstudios.com/default-user/titus/


r/JavaScriptHelp • • Dec 02 '20

❔ Unanswered ❔ Javascript code for button to remove content from html as it loads?

1 Upvotes

There's a website that I want to google translate using Chrome, but the creator has added <meta name="google" content="notranslate"/> to the html. This prevents Chrome from popping up asking if it can autotranslate the page. I can inspect the element and remove it, but Chrome won't pop up because it only does so when the page loads. Can I get around this with javascript? I've seen it done for other purposes with a bookmark saved on the bookmarks bar, but I can't figure out how to adapt it here. Thanks.


r/JavaScriptHelp • • Dec 24 '20

❔ Unanswered ❔ Issue with Return/Resolve

2 Upvotes

I have a function that is preforming a series of checks, and if all checks are passed it prints it to the console and executes another function, if not - it returns 606 and the rest of the code displays an error.

The expected result is 606, as I am intentionally making it fail the checks. Instead, my console is completely empty and it does not return 606.

This is my code, any help in debugging or a fix would be greatly appreciated.

exports.userBirthday = async function(username, age1) {
  console.log("Age is being validated")
  return new Promise((resolve, reject) => async function() {
  if (age1 > 117) resolve(606);
  const hashedUsername = await main.hashUsername(username);
  const currentAge = await main.userAge(username)
  console.log(currentAge)
  db.get(`SELECT Points, Modified FROM users WHERE Username = '${hashedUsername}'`, async function(err, result) {
    console.log(currentAge)
		if (currentAge == 404) {
      main.update(username, age1, 0);
      return;
    } else if (age1 > (currentAge + 1) || age1 < currentAge) {
      resolve(606);
      return(606);
		} else
		if ((result.Modified = main.date())) {
      resolve(606);
      return(606);
    } else {
      console.log("No issues found")
    main.update(username, age1, result.Points);
    }
  });
});
}

I have 1 thing in my console from this function: "Age is being validated" and after that all output stops - not even a return or resolve.

How would I go about fixing this?


r/JavaScriptHelp • • Dec 09 '20

❔ Unanswered ❔ How to Build a PWA in Vanilla JS?

1 Upvotes

I was scrolling through the internet for help to build a PWA in Vanilla JS and found this tutorial.

Sharing it here because I believe it might be useful for others too. Also, let me know if you know more such tutorials. It would be a great help :)

https://www.loginradius.com/blog/async/build-pwa-using-vanilla-javascript/


r/JavaScriptHelp • • Dec 16 '20

❔ Unanswered ❔ I want to show pop up based on months. Like if it's january then i need to show jolly january , February then fantastic feb and so on based on system date i need to show user this popups. Based on months.

1 Upvotes

What's the best way to implement the above functionality ?


r/JavaScriptHelp • • Dec 05 '20

❔ Unanswered ❔ Tabbing to next input in a form where there are extra buttons in the <form>

1 Upvotes

I have a form that, give or take, looks like this

<form>

<input type="password" />

<button>Show</button>

<input type="password" />

</form>

Basically, there are two password inputs and a button (which in reality is positioned absolute inside of the input). The button can toggle (show/hide) the password.

When using tab to jump from input #1 to input #2, the first time you hit tab it focuses on the button rather than going to input.

Is there a property on the button I'm missing that will "take it out of the form", so that it doesn't recognize the button as a form input that can be tabbed to?


r/JavaScriptHelp • • Nov 20 '20

❔ Unanswered ❔ Is there a free video surveillance web server with API for js applications?

1 Upvotes

I would like to buy a computer and cameras, and install a ready-made server on it. I'll write the client myself.

It is necessary to have recognition of movement and faces

I will also consider paid options, but I wonder if there are free and good ones or maybe there are cameras that are sold with a ready-made web server? Even a complete video set, but for everything to work offline.

The server distributes its wifi, and the client connects from a mobile browser


r/JavaScriptHelp • • Dec 15 '20

❔ Unanswered ❔ Trying to figure how what this replace () is doing

1 Upvotes

I'm looking into some code and I can't figure out what this replace function is actually replacing:

replace(/\=+$/, '');

If anyone could help I'd be so thankful!


r/JavaScriptHelp • • Dec 14 '20

❔ Unanswered ❔ & Breaking Output

1 Upvotes

I've got a script to capture user input and place it into a variable, however if the user puts in a "&" sign it breaks the whole thing. Thank you in advance for any advice on handling the '&' sign in the "companyName" variable you can give me. See below...

var cCCAddr = "";

var cSubLine = "Bill To - Form Submission";

var companyName = this.getField("Company").value;

var cBody = "ADD \n"

+ "Company: \t \t \t"

+ companyName

+ "\n"

+ "Requestor: \t \t \t"

+ this.getField("Requestor").value

+ "\n" + "Date: \t \t \t \t"

+ this.getField("Date").value

+ "\n"

+ "Bill to Name: \t \t \t"

+ this.getField("Bill to Name").value

+ "\n"

+ "Address: \t \t \t"

+ this.getField("Address").value

+ "\n"

+ "City: \t \t \t \t"

+ this.getField("City").value

+ "\n"

+ "State: \t \t \t \t"

+ this.getField("State").value

+ "\n"

+ "Zip Code: \t \t \t"

+ this.getField("Zip Code").value

+ "\n"

+ "Country: \t \t \t"

+ this.getField("Country").value

+ "\n"

+ "Payment Terms: \t \t"

+ this.getField("Payment Terms").value

+ "\n"

+ "Address Type: \t \t \t"

+ this.getField("Address Type").value

+ "\n"

+ "Payment Terms: \t \t"

+ "7"

+ "\n"

+ "Customer Price Group \t \t"

+ this.getField("Customer Price Group").value

+ "\n"

+ "Print Prices on Packing List: \t"

+ this.getField("Print Prices on Packing List").value

+ "\n"

+ "Freight Handling Code: \t \t"

+ this.getField("Freight Code").value

+ "\n"

+ "Zone Number: \t \t \t"

+ this.getField("Zone Number").value

+ "\n"

+ "Carrier Number: \t \t"

+ this.getField("Carrier Number").value

+ "\n"

+ "Route Code: \t \t \t"

+ this.getField("Route Code").value

+ "\n"

+ "Stop Code: \t \t \t"

+ this.getField("Stop Code").value

+ "\n"

+ "Sales Person: \t \t \t"

+ this.getField("Sales Person").value

+ "\n"

+ "Phone: \t \t \t \t"

+ this.getField("Phone").value

+ "\n"

+ "Contact: \t \t \t"

+ this.getField("Contact").value

+ "\n"

+ "Email Invoices: \t \t \t"

+ this.getField("Email Invoices").value

+ "\n"

+ "Email Address: \t \t \t"

+ this.getField("Email Address").value

+ "\n"

+ "Notes: \t \t \t \t"

+ this.getField("Notes").value;

var cEmailURL = "mailto:[email protected]?cc=" + cCCAddr + "&subject=" + cSubLine + "&body=" + cBody;

this.submitForm({cURL: encodeURI(cEmailURL), cSubmitAs:"PDF", cCharSet:"utf-8"});


r/JavaScriptHelp • • Nov 20 '20

❔ Unanswered ❔ Why does my code not execute?

1 Upvotes

Hello!

I tried to implement a code with Webflow. This added a <script> tag to my webpage with the following code, but it doesn't execute anything at all. I also dont get any error messages. I would appreciate some help.

<script rel="preload" type="text/javascript" src="https://code.jquery.com/jquery-1.10.0.min.js">

  $(function(){
    console.log("hello");
    var userLang = navigator.language || navigator.userLanguage;
  alert(userLang);
  alert('Hello');
    if (userLang == "en") {
        window.location.ref = "https://www.XXX.ch/en";
    }
  else if (userLang == "fr") {
        window.location.ref = "https://www.XXX.ch/fr";
    }
  else if (userLang == "it") {
        window.location.ref = "https://www.XXX.ch/it";
    }
    else {
        window.location.href = "https://www.XXX.ch";
    }

  });
</script>

r/JavaScriptHelp • • Nov 16 '18

It’s super simple but I need help

1 Upvotes

<!doctype html>

<!-- lab8.html by Mei —> <!-- Lab8.html displays a countdown from a specified number -->

<html><head> <title> Lab8 </title>

<script type "text/javascript"> Function countdown() // Assumes: countBox contains a non-negative integer // Results: displays a countdown from that number in outputDiv {//start function block var count; count=parseFloat(document.getElementById(('countBox').value); var result: '' ; while (count > 0) { //start while loop result = result + count + '<BR>'; count = count -1; } //close while loop document.getElementByld('outputDiv').innerHTML =result + 'BLASTOFF!’; } //close function block </script>

</head>

<body bgcclor: “#FFF0F5”> <h2> Lab8 displays a countdown from a specified number </h2>

<p> Start of the countdown: <input type=“text” id=“countBox” size=4 value=""> </p> <input type="button" value="Begin Countdown" onclick="countdown();" /> <hr /> <div id="outputDiv"></div> </body> </html>


r/JavaScriptHelp • • Apr 06 '18

How to make my sprite scroll smoothly frame by frame in my parallax scroll framework?

1 Upvotes

I have created a parallax framework and I am trying to get my sprite to change frames when I scroll. Right now when I scroll, I can see each frame but it gets cut off. I want it to look like he's actually dancing.

Here is a preview : CodePen

How do I get it to scroll smoothly by each frame?


r/JavaScriptHelp • • Nov 15 '18

Can you help me with my javascript issue

1 Upvotes

I want a javascript injection for swagbucks.com Home page where you check your sb I want to locally manipulate the website and increase my swagpoints if you have ever used this website before you will know what I am talking about

This is an amazing website for earning a bit more here is the link you will enjoy it

http://www.swagbucks.com/p/register?rb=48607558


r/JavaScriptHelp • • Apr 05 '18

JavaScript Jungle

2 Upvotes

I decided to learn how to code a few months ago and after choosing JavaScript as my first computer language I am starting to doubt my choice. It seemed understandable at first until I realised just how many other languages I was going to have to learn in order to make my JavaScript useful. I know that technically I only need HTML, CSS and JavaScript but realistically there's also jQuery which I know is not classed as a language, .JSON of which I know little about and a few others I can't remember the names of. They all interact in some way. Can anyone out there give me some advice as to whether I have chosen wisely and should continue to grapple around in this JavaScript Jungle or whether I should try to learn another language first. By the way, I know what you are thinking: "Proper use of the English language would be a good start!".


r/JavaScriptHelp • • Nov 21 '18

Help finding max of arrays

1 Upvotes

Hello, for some reason this might be super simple (and I'm sure it is) but I can't seem to have something that actually works as I want it to : Here's what I wan't to do :

let T = [[-5,8,-4],[5,-3,15],[1,11,-4]]; //random numbers for example
let tabPG=[];
tabPG.push(Math.max.apply(Math, T.map((i)=>i[0])));
console.log(tabPG);

This outputs me [5] as you would expect. Here's the thing, I would like to get rid of that '0' for something that would output me [5,8,15]. Been struggling for some hours somehow so I'd like to know how to do it, or at least get some hints.

Thank you for your time ! :)


r/JavaScriptHelp • • Jun 05 '18

Replacing br with newline in this JS

1 Upvotes

https://pastebin.com/SvMRj9cQ

I added line 8 and also tried

aux.setAttribute("value", document.getElementById(elementId).innerHTML.replace(/<br\s*[\/]?>/gi, "\n"));


r/JavaScriptHelp • • Jun 12 '18

Looking for help with Javascript and CSS

1 Upvotes

Just wondering what the basic JS code would be that when you fill out a single field in an online form, the JS would post whatever's in that field on another web page and next to it insert a little NEW icon with a green background.


r/JavaScriptHelp • • Sep 28 '21

❔ Unanswered ❔ How to update the form submit behavior via JavaScript and add a function to open in a new tab?

1 Upvotes

Essentially I have this script from Think Reservations, which takes a bit of html and updates it to create booking widgets according to this documentation. But I cannot for the life of me figure out how to make the link open in a new page. I believe I need to add something to the following chunk of code, but it's way above my head. If anyone could help or even just point me in the direction of some helpful documentation, I'd really appreciate it. Thanks!

key: "handleSubmit",
value: function(t) {
        var e = this;
        t.preventDefault(), this.verifyForm() && ! function() {
                var t = e.props,
                        n = t.shortName,
                        r = t.unitId,
                        i = e.refs.startDateAlt.value,
                        o = e.refs.endDateAlt.value,
                        a = parseInt(e.refs.numberOfAdults.value, 10),
                        u = parseInt(e.refs.numberOfChildren.value, 10),
                        s = [];
                _.times(u, function(t) {
                        var n = parseInt(e.refs["childAge-" + t].value, 10);
                        s.push(n)
                });
                var c = "https://secure.thinkreservations.com/" + n + "/reservations/availability?start_date=" + i + "&end_date=" + o + "&number_of_adults=" + a + "&number_of_children=" + u;
                s.length && (c += "&child_ages=" + s.join(",")), r && (c += "&roomId=" + r), "undefined" != typeof _gaq ? (_gaq.push(["_setAllowLinker", !0]), _gaq.push(["_link", c])) : window.location = c
        }()
}

r/JavaScriptHelp • • Sep 29 '21

✔️ answered ✔️ Please help

1 Upvotes

I'm very new and know almost nothing. Please help.

https://stackoverflow.com/questions/69383297/javascript-html-im-trying-to-increase-a-value-when-clicking-and-value-retur

^^^(My question)^^^

EDIT: Someone answered the question