I am creating a number guessing game based on the user inputting the maximum number. I was wondering how I could generate the random number only once until the user guesses correctly? I messed around with creating another function and nesting functions however I could not get anything solid to work. Currently…
Tag: javascript
TextInput gets unfocused after typing each character
I’m using React to build a form and I’m trying to filter a list with the SearchInput (which works the same as TextInput) located in the child component Header. But everytime I type a character the SearchInput gets unfocused Answer Oh, I think I can see the problem now – it’s the way yo…
What is this structure in javascript return({object}={})=>{more code}?
I’m trying to understand what this code is doing, it’s from a nodejs. I don’t understand what is this structure is doing return({object}={})=>{more code} you can find the repository here: https://github.com/howardmann/clean-node/blob/master/models/teacher/teacher.js Answer In addition to …
Calculation not being performe properly in JavaScript
I have the following code that is converting characters entered in an input field into other characters (namely, entering an e or and E and converting it to a 3, likewise for a t or T into a 7). I am also calculating the percentage of the characters that were converted, but my calculation is not being perform…
Rails 7 JavaScript event listeners stop working after browser back?
I have rails 7 app where I’m trying to build a search bar using either tom-select or slim-select. My issue reproduces no matter which library I’m using therefore it must be the issue on my rails side. app/views/cities/index.html.erb and this is my js controller (in this case I’m using tom-se…
Building a keyboard and missing onclick event
I’m building a virtual keyboard with vanillla javascript but don’t know where to add the onclick event listener to the buttons or how to grab them. I have a printKeys function that loops thru the array and prints them onload, and I have an unfinished typeKeys function where I’m trying to gra…
How to convert an array of strings into a number?
I’m fetching data from an API which returns currency exchange rates like so: I was able to manipulate the fetched data using: const rate = Object.values(data).splice(11,5); which returns 1.044 However, my next problem comes when trying to parseFloat this object into a number.. for some reason it only re…
move a circle from one point to another
I’m new to leaflets and am trying to circle the map when clicked. I want conditions like the following: Circle moves from one point to another when clicked on the map (If the circle already exists and there is only one circle) Directly Zoom on where the circle is made However I have the following proble…
How to insert a tag’s text into its parent element as a data attribute?
I have this HTML: How do I make a loop that takes the inner text of every p tag and puts it into the data-item attribute of its respective div parent like this: Answer Loop over the divs. In each div, use querySelector() to find the nested p, get its contents with .textContent, and assign that to the div̵…
Reading the parameter values off the current URL on page load
I realize retrieving search params from the URL is a commonly asked Question but I am running into an issue with using URLSearchParams(window.location.search) because I believe it is searching for a ? and my url contains & as separators between values. my url will look something like this http://localhost…