I’m having an issue understanding how I might go about using the this keyword to refer to a DOM element that is has been clicked, but also using that inside a class where this usually refers to the instance of that class. Here’s a snippet of the relevant code: The issue I’m having is that it…
Tag: javascript
I am trying to solve a challenge from jshero.net
I am trying to solve a challenge from jshero.net Write a function add that adds an element to the end of an array. However, the element should only be added if it is not already in the array. Example: add([1, 2], 3) should return [1, 2, 3] and add([1, 2], 2) should return [1, 2]. why didn’t work this co…
How to redirect to another page using on keypress in nextjs?
I need to redirect users using onkeypress in nextjs. I have a search input where users can type and then press enter key to go to the other page. What I’ve tried: i would appreciate your help. Answer You can use the useRouter hook from next – https://nextjs.org/docs/api-reference/next/router Try c…
Javascript pseudo-zoom around mouse position in canvas
I would like to “zoom” (mouse wheel) a grid I have, around the mouse position in canvas (like Desmos does). By zooming, I mean redrawing the lines inside the canvas to look like a zoom effect, NOT performing an actual zoom. And I would like to only use vanilla javascript and no libraries (so that …
code event[] calendar in laravel 8 not working
I created a calendar with laravel 8 and PHP 8,it is running ok in php 7 but I have to upgrade to php 8 because of the demands of the times I have successfully saved data in the database but the data in mysql does not appear in the calendar, even though I have used event[], I have checked that
Chart.js: Why are there two y axes in my line graph?
I’m using chart.js to build a line graph. I can’t figure out why there are two y-axes on my graph. I also tried changing the color of the tick labels to white but it isn’t working either. Thanks for your help! Here’s the preview of my code: https://codepen.io/suminohh/pen/vYROrEx Answe…
for loop to multiply index 0 with 1, index 1 with 2, index 2 with 3
how could i generate a loop that iterates through a array, and its just multiplying the next index? example: array= [0,1,2,3,4,5] i know that i need to have a nested loop, but I cannot find the solution. Answer The problem with your current implementation is that you are looping over every index twice: once f…
Unable to load CSS file within nodeJS app
I have an app that I followed from a tutorial for the backend in nodeJS and Express. My connection to MongoDB via Mongoose is working. However, I’ve been trying to add a front-end- at the moment- just a simple html/ejs/css form. My endpoints are loading in localhost but only the html/ejs is rendering. M…
For Loop while referring to an array with Length
I’m very new to javascript and have just recently learned about For loops. I have a variable that consists of an array containing a bunch names, and I would like to add last names to each of them. I wrote the code as shown below and have a few questions. Result : Questions: About the second statement fo…
Make the input and button on the same line
I’m making a todo list app using react and chakra ui. I want to make the input and the button on the same line. This is what i get: photo I want to make something like this: photo My Code: App.js: Todo.js: Answer removing the margin top from input should fix it: