Global variable logs as undefined when event fires

In the code I wrote, overlayBtn.addEventListener triggers nested event amtBtn.addEventListener to grab quantiy.value from a local scope and insert it into a global variable getquantity. Then a <p> element will be created to hold getquantity and attached to listContainer .

However, when I console log getquantity in overlayBtn.addEventListener it logs as undefined, thereby the code cannot proceed to add the value in the created <p> element. I don’t know why this is happening. Is there a way to make getquantity get the intended value and not come up as undefined? I would really appreciate if you guys could help me out in this one.

Here’s the code:

JS

const overlay = document.querySelector('.overlay');
const overlayBtn = document.querySelector('.overlay-btn');
var quantity = document.querySelector('.quantity');
var amtBtn = document.querySelector('.amt-btn');
const formAmount = document.querySelector('.form-amount');
const sucMsg = document.querySelector('.suc-msg');
const listContainer = document.querySelector('list-container');
let getQuantity;

overlayBtn.addEventListener('click', function(){
  overlay.style.display = "block";
  amtBtn.addEventListener('click', function(e){
    e.preventDefault();
    getQuantity = quantity.value; //Value gotten from local scope
    formAmount.classList.add('hide-form-amount');
     sucMsg.classList.add('show-suc-msg');
     setTimeout(returnNormal, 1000);
     function returnNormal(){
      overlay.style.display = "none";
      sucMsg.classList.remove('show-suc-msg');
      formAmount.classList.remove('hide-form-amount');
     }
    });
    console.log(getQuantity); //Will come up as undefined
    const para = document.createElement('p');
    para.innerHTML = `${getQuantity}`;
     listContainer.prepend(para);

  });

CSS

.overlay-btn{
  padding: 50px;
}

.overlay{
  position: fixed; 
  display: none; 
  width: 100%; 
  height: 100%; 
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0,0,0,0.5); 
  z-index: 2; 
  cursor: pointer; 
  display: none;
}

.showOverlay{
  display: block;
}

.form-amount{
  margin: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  background-color: #2C8F77;
  visibility: visible;
}

.hide-form-amount{
  visibility: hidden;
}

.suc-msg{
  margin: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  background-color: #2C8F77;
  color: white;
  visibility: hidden;
}

.show-suc-msg{
  visibility: visible;
}

.list-container{
  height: 500px;
  width: 300px;
  background-color: #2C8F77;
  color: aliceblue;
  overflow: scroll;
}

HTML

<button class="overlay-btn">add to list</button>
  
              <div class="overlay">
                <div class="amountPopUp">
                  
                  <form class="form-amount">
                    <label for="quantity">Quantity:</label>
                    <input type="number" class="quantity" name="quantity" min="1" max="100">
                    <input type="submit" class="amt-btn" value="Enter" name="quantity">
                  </form>
                  <div class="suc-msg">
                    <h4>Item(s) added successfully</h4>
                  </div>
                </div>
              </div>
              <div class="list-container"></div>

how to define url in background-image when image is not from public folder

- public
 - src
   - assets
      - icons
        - plus-purple.svg

This is my file structure at the moment.

I have to use 'background-image:url()' css property now.

I don’t know what the correct url link would be, if I wanna import plus-purple.svg in mycase.

My bottom line is that,
I’d like to know proper url link when I try to import image from NOT public folder! (for my background-image css property)

thank you so much!

I’M USING NEXT.JS btw!

Only render visible object faces Three JS

I’m trying to render a world with very many blocks, but the performance has become very bad.
So I was wondering if there is a possibility to only render objects / object faces that are visible for the camera.

Here is the code I use for creating the world

for (let x = 0 ; x < this.worldWidth; x++){
    for (let z = 0; z < this.worldWidth; z++){
        let y = this.getNoiseY(x, z)

        let grassblock = new Block(BlockID.GRASS_BLOCK)
        grassblock.setPosition(x - this.worldWidth / 2, y, z - this.worldWidth / 2)
    }
}

Every block has a BoxBufferGeometry and a MeshStandardMaterial.
Are there any ways to optimize those performance issues?

Regex for input hashtags [duplicate]

I’m using regex to validate HTML input field. Hashtags (RU-EN) mast be devided by space and not include digit as first symbol.
Here the expression: https://regex101.com/r/g2Z4fD/1

If hashtags writted correctly, input border goes green, if not- red.
My regex works well, but only for first tag in string.
So, question is, how to make my regex recognize and validate all tags in string. Thanks.

              var y;
              y = document.getElementById("user_tags").value;
              var x;
              x = new RegExp('(?:(?<=s)|^)#(w*[a-zA-Zа-яёА-ЯЁ_]+w*)+');
              if (y !== "text") {
                if (x.test(y))  {

                document.getElementById("user_tags").style = 'border-color:green';  
               
              
                }
              
                else {
              
                  
                 document.getElementById("user_tags").style = 'border-color:red';
                
                }
              
               }
              
              }
              
              </script> ```




React useState rerender even if i pass the same reference?

What I know is that useState will not rerender if we pass the same state, and I test it by myself, but it worked only the first time the component rerendered, with an initial state passed to useState.
But in the example below, the useState rerenders the component even if I pass the same reference, also useEffect knows that the state does not changed.
The picture with console.logs shows that behavior.

const arr = [
  { name: 'Khaled', id: 0 },
  { name: 'Mohamed', id: 1 },
  { name: 'Ahmed', id: 2 },
  { name: 'Mohsen', id: 3 },
];

function App() {
  console.log('num $1');

  const [same, setSame] = useState({});

  useEffect(() => {
    console.log('num $3');

    const test = arr.find((el) => el.id === 0);
    console.log(Object.is(same, test));
    setSame(test);
  }, [same]);

  console.log('num $2');

  return <div>welcome</div>;
}

enter image description here

React Native Firebase Analytics window.document.getElementsByTagName Problem

I want to connect firebase analytics to my react native project, but when I write this code in my app,

import {initializeApp} from 'firebase/app'
import {getAnalytics} from 'firebase/analytics';

const firebaseConfig = {

.
.
.

};

const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);

i am facing this error in my terminal

Possible Unhandled Promise Rejection (id: 0): TypeError: undefined is
not an object (evaluating ‘window.document.getElementsByTagName’)

Riot API problem with missing modules TLS, NET, DNS

i have big problem with my project, when i’m uploading riot api to my file

import { RiotAPI, RiotAPITypes, PlatformId } from "@fightmegg/riot-api";

and trying to use it, exactly like on github, i get insta error in console, which shows that i don’t have modules : tls, net, dns. I tried to install them and import, but it was still error.
I’m trying to find user, by world and nickname so i’m using this code

    const config: RiotAPITypes.Config = {
  debug: false,
  cache: {
    cacheType: "local", // local or ioredis
    client: `localhost:3000/settings`, // leave null if client is local
    ttls: {
      byMethod: {
        [RiotAPITypes.METHOD_KEY.SUMMONER.GET_BY_SUMMONER_NAME]: 5000, // ms
      },
    },
  },
};

const rAPI = new RiotAPI("RGAPI-37aee947-8e88-4f4c-b420-f7828d58e815", config);

(async () => {
  const rAPI = new RiotAPI("RGAPI-37aee947-8e88-4f4c-b420-f7828d58e815");

  const summoner = await rAPI.summoner.getBySummonerName({
    region: PlatformId.EUW1,
    summonerName: "Demos Kratos",
  });
})();

and problem which i see looks like this :

Module not found: Can’t resolve ‘net’

Import trace for requested module:
./node_modules/ioredis/built/cluster/index.js
./node_modules/ioredis/built/index.js
./node_modules/@fightmegg/riot-api/dist/esm/cache.js
./node_modules/@fightmegg/riot-api/dist/esm/index.js
./src/pages/settings/index.tsx

Module not found: Can’t resolve ‘tls’

Import trace for requested module:
./node_modules/ioredis/built/index.js
./node_modules/@fightmegg/riot-api/dist/esm/cache.js
./node_modules/@fightmegg/riot-api/dist/esm/index.js
./src/pages/settings/index.tsx

Module not found: Can’t resolve ‘dns’

Import trace for requested module:
./node_modules/ioredis/built/cluster/index.js
./node_modules/ioredis/built/index.js
./node_modules/@fightmegg/riot-api/dist/esm/cache.js
./node_modules/@fightmegg/riot-api/dist/esm/index.js
./src/pages/settings/index.tsx

Clusters, and markers randomly loading onPageLoad *MapBox*

So what I want is for all the clusters and markers to be visible from the start. that is, when entering the page. But that’s not the case.

Everything that should be on the map loads completely sporadically. Like when i hit hard refresh some times it suddenly wont load.

const bounds = Map.current
    ? Map.current.getMap().getBounds().toArray().flat()
    : null;

The code block above might be the issue. When the map is empty of markers and clusters this code block logs null aswell. How can i use this in useEffect if that could work?

Cluster code:

const points = useMemo(
    () =>
      data.map((store) => ({
        type: "Feature",
        properties: {
          cluster: false,
          storeId: store.id,
          category: store.country_code,
        },
        geometry: {
          type: "Point",
          coordinates: [store.coords[0], store.coords[1]],
        },
      })),
    [data]
  );

  const bounds = Map.current
    ? Map.current.getMap().getBounds().toArray().flat()
    : null;

  const { clusters } = useSupercluster({
    points,
    bounds,
    zoom: viewport.zoom,
    options: { radius: 75, maxZoom: 20 },
  });

Before and after refresh/move on map/saving code/pretty much anything

Unloaded

Loaded

So when i console log this:
Console log clusters

Before:

Before loading

After:

After

To find maximum number of dolls the person can collect

You are given a non empty array A of n integers a0,a1,…..,an-1.this array represents number of dolls on the consecutive positions. You are also given integers k and m k>=0 and m<n k is the current position of the person m is the number of moves in one move the person moves to adjacent position he collects all the dolls on that position the goal is to calculate maximum number of dolls the person can collect in m
Moves the person cannot change the direction more than once

Why this auto-update searcher is not working correctly? (Laravel + Vue)

I want to create a simple searcher and I want to be auto responsive without using a button. I want if you write here, it search automatically with that characters.

I want to do the easiest way to create it, nothing complicated or install another items to do it.

I think the hard part is done, but for some reason it gives me the next error:
GET http://webpage.test:8080/inscripcioneswebs/buscador?buscador=A 500 (Internal Server Error)

Any idea?

web.php

Route::resource('inscripcioneswebs', InscripcionesWebController::class);

Route::get('inscripcioneswebs/buscador', 'InscripcionesWebController@buscador');

InscripcionesWebController.php

public function index()
    {
        $inscripcioneswebs = Inscripciones_Web::orderBy('INS_WEB_ID_WP', 'desc')->paginate(10);

        return view('inscripcioneswebs.inscripcioneswebs')->with('inscripcioneswebs', $inscripcioneswebs);
    }

public function buscador(Request $request)
    {
        $buscador = $request->buscador;

        $inscripcioneswebs = Inscripciones_Web::select('INS_WEB_ID')
                    ->where('INS_WEB_ID', 'LIKE', '%' . $buscador . '%')
                    ->paginate(10)
                    ->get();

        return view('inscripcioneswebs.inscripcioneswebs')->with('inscripcioneswebs', $inscripcioneswebs);
    }

incripcioneswebs.blade.php

<div id="inscripcionweb">
    <div>
        <form action="{{ route('inscripcioneswebs.index') }}" method="get">
            <input type="text" name="buscador" id="buscador">
        </form>
    </div>

    <div id="resultados"></div>

    <table class="datatable">
        @foreach ($inscripcioneswebs as $inscripcionesweb)
            (The table DATA)
        @endforeach
    </table>
</div>

inscripcionweb.js

new Vue({
    el: '#inscripcionweb',

    mounted: function() {
        document.getElementById("buscador").addEventListener("keyup", function() {
            fetch(`/inscripcioneswebs/buscador?buscador=${document.getElementById("buscador").value}`, {
                method: 'get'
            })
            .then(response => response.text())
            .then(html => {
                document.getElementById("resultados").innerHTML += html
            })
            .catch(error => console.log(error))
        })
    },
});

how to move the circles with an array?

I wanna have six linearly moving dots — three of them horizontally, others vertically using an array.

here is my code:

let c;
let cspeed = 4 

function setup() {
  createCanvas(800, 800);
  c=0
}

function draw() {
  background(220);
 
  ellipse(c, height / 4, 50, 50);
  ellipse(c, height / 2, 50, 50);
  ellipse(c, height / 9, 50, 50);
  ellipse(height / 4, c, 50, 50);
  ellipse(height / 2, c, 50, 50);
  ellipse(height / 9, c, 50, 50);
  c+=cspeed;

  if (c > width || c < 0) {
    cspeed *= -1;
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>

Why don’t we make HTML DOM as optional choice for making a website? [closed]

You might think ,this is a ridiculous idea, but hear me.

We will all agree that
HTML was first designed to represent a DOCUMENT style.
but now

We are making web apps (PWA’s).

—mainly for 2 reasons.
Cross platform and Javascript and Typescript ( loved by many devs)

The DOM

I believe that the DOM is outdated especially in the era of wasm. If you are looking for speed… isn’t DOM the bottleneck?

An alternative approach to DOM

nowadays many web apps like google docs are rendering a huge part of the UI in a canvas.

checkout makepad and the demo for similar thing

I think the idea is great , so why don’t we have a official way to make apps this way and

alert isn’t returning value of cell 1,24

im using app script and google sheets.

In app script i have this code

var sheet = SpreadsheetApp.getActiveSheet()
let ui = SpreadsheetApp.getUi();
return ui.alert(sheet.getRange(1,24).getValue.toString())

its returing this

function () { [native code] }

Any Ideas?