javascript: “can’t access variable before initialization” if I break the code into separate function

I’ve found several articles, both here on SO and elsewhere that mention this error message, but none that I can apply to my specific situation. Can anyone help me understand what’s going on?

If I write my code like so:

selDocument.group_selected = function ($, anchor) {
    let tmpitems = $(".chkSelectedField:checked");
    if (tmpitems.length > 1) {
        let items = [];
        $(tmpitems).each(function (a, b) {
            items.push($(b).val());
        });
        if (typeof anchor != 'undefined') {
            items = items.filter(el => el != anchor);
        } else {
            anchor = items.shift();
        }
        console.log("57199516 items, anchor", items, anchor);

it works fine, but if I take those blocks and break them into their own function:

selDocument.group_selected = function ($, anchor) {
        let tmpitems = $(".chkSelectedField:checked");
        if (tmpitems.length > 1) {
            let retval = selDocument.create_items_array($, tmpitems, anchor);
            let items = retval.items;
            let anchor = retval.anchor;
            console.log("57199516 items, anchor", items, anchor);
...
selDocument.create_items_array = function ($, tmpitems, anchor) {
    let items = [];
    $(tmpitems).each(function (a, b) {
        items.push($(b).val());
    });
    if (typeof anchor != 'undefined') {
        items = items.filter(el => el != anchor);
    } else {
        anchor = items.shift();
    }
    return JSON.parse({ 'items': items, 'anchor': anchor });
};

I get “Cannot access ‘anchor’ before initialization.”

Map object not setting values after execution of function

I have a function below where the purpose is to parse multiple local csv files. For each parsed csv file, I then grab 1-5 random elements. Since the CSV parser outputs the data in a nested array structure ([['a'], ['b'], ['c']]), I further process the data and extract the individual array elements to push into the final array.

My final goal is to update the values in the types map by passing in the respective arrays for each of its keys

let health = createHealthData();
console.log(health, 'final output')

function createHealthData() {
  let types = new Map();
  types.set('allergies', '');
  types.set('medications', '')
  let start = 1;
  let limit = 5;

  for (let key of types.keys()) {
    let randNum = Math.floor(Math.random() * (limit - start + 1) + start); // Generates random numbers between start and limit
    let file = fs.createReadStream(path.resolve(__dirname, `${key}.csv`))

    Papa.parse(file, {
      header: false,
      complete: (results) => {
        let first = []
        let data = results.data;

        let final = [];
        for (let i = 1; i <= randNum; i++) {
          first.push(data[Math.floor(Math.random() * data.length)])
        }

        first.forEach((x) => {
          x.forEach((y) => {
            final.push(y)
          })
        })
        types.set(key, final);
        console.log(types);
      }
    })
  }
  return types;
}

My function parses and processes the csv files fine, but it refuses to update the existing keys in the map once I return the types map

For instance, my output at console.log(types) gives me:

Map(2) {
   allergies => ['Banana Allergy'],
   medications => ['Opana ER', 'Atrovent HFA']
}

which is what I intend to pass out of the function.

However, upon viewing the health variable after the function finishes executing, the output is:

Map(2) {'allergies' => '', 'medications' => ''} final output

as if the line types.set(key,final) never executed at the end of the function. I’m struggling to find what the source of this bug is and based on the scope of the types variable in the function, I’m not seeing where it might be overwritten.

How would I optimize this piece of code to scale to 100,000 unique users/stock tickers?

Sending price alerts based on a users set alert pulled from a database, then making a call to get the current price.

I am looking for a way to scale this. I am using for.. of.. because it will be asynchronous. Please correct me if i am wrong there.

const sendPriceAlert = () => {
    const userStockAlerts = [
        {
            name: "Joe323",
            ticker: "AAPL",
            alert: "> 170"
        },
        {
            name: "Sam525",
            ticker: "AAPL",
            alert: "< 130"
        },
        {
            name: "Mark548",
            ticker: "AMZN",
            alert: "> 3000"
        },
        {
            name: "Seth613",
            ticker: "AAPL",
            alert: "> 160"
        }
    ]
    const uniqueTickers = [
        ...new Set(userStockAlerts.map(alert => alert.ticker))  
    ];

    for (const ticker of uniqueTickers) {
        const currentPrice = 1000 // API call returns ticker current price getPrice(AAPL)

        const matchingAlerts = userStockAlerts.filter(
            alert => alert.ticker == ticker
        );
        
        for (const alert of matchingAlerts) {
            if (eval(`${currentPrice} ${alert.alert}` )) {
                console.log(`${alert.name}: ${ticker} is ${alert.alert[0] == '>' ? 'above' : 'below'} $${alert.alert.split(' ')[1]} `)
            }
        }
        
    }

}

sendPriceAlert();

Why does my mousefollow method not work on different browsers

Here is a link to the code pen
https://codepen.io/shahman28/pen/mdXraRE

This is a part of a larger project that I am working on. I am attempting to place circles when the mouse is clicked. As you can see in the codepen above the mouse follows well and places the circles at the correct locations, but when I try to do it in browser the cursor has an offset from the mouse and the circles are placed incorrectly. In firefox it is completely arbitrary, but in chrome it places them in the location of the cursor(which is in the incorrect location). I am recycling some code from previous projects so that is why there is the border in the html and css.

html:

<!DOCTYPE html>
<html lang="en">
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]>      <html class="no-js"> <!--<![endif]-->
<html>
    <head>
        <meta charset="utf-8">
        <meta name = "viewport" content="width=device.width, initial-scale=1.0">
        <title>Tower Defense</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <button onClick = "start()">Start Combat</button>
        <canvas id="canvas1"></canvas>
        
        <script src="script.js"></script>
    </body>
</html>

css:

body {
  background: black;

}

#canvas1 {
  border: 1px solid black;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 900px;
  height: 600px;
  background: white;    
}

javascript:

const canvas = document.getElementById('canvas1');
const ctx = canvas.getContext('2d');

points = [];
class Mouse {
  constructor(c) {
    this.x = 0;
    this.y = 0;
    this.easing = 0.05;

    let rect = canvas.getBoundingClientRect();
    
    canvas.onmousemove = e => {
      this.x = e.clientX - rect.left;
      this.y = e.clientY - rect.top;
    }
  }

}

class Point {
  constructor(x, y, color){
    this.x = x;
    this.y = y;
    this.color = color;
  }
  
  draw () {
    ctx.fillStyle = this.color;
    ctx.beginPath();
    ctx.arc(this.x, this.y, 5, 0, 2*Math.PI);
    ctx.stroke();
    ctx.fill();
  }
}

function random_hex_color_code() {
  let n = (Math.random() * 0xfffff * 1000000).toString(16);
  return '#' + n.slice(0, 6);
};

canvas.addEventListener('click', function(e){
  
  let rect = canvas.getBoundingClientRect();
   x = e.clientX - rect.left
   y = e.clientY - rect.top;
   point = new Point(x, y, '#FF0000');
   points.push(point);
})
w = canvas.width = window.innerWidth,
h = canvas.height = window.innerHeight,
mousePosition = new Mouse(canvas);


function animate() {
    
    ctx.fillStyle = '#4A7DB9';
    ctx.beginPath();
    ctx.arc(mousePosition.x, mousePosition.y, 5, 0, Math.PI * 2);
    ctx.closePath();
    ctx.fill();
}
function handlePoints() {
  for (let i =0; i < points.length; i++){
    points[i].draw();
  }
}
function render() {
  ctx.clearRect(0, 0, w, h);
  handlePoints();
  animate();
  window.requestAnimationFrame(render);
}

render();

Does anyone know how to make it so that the the cursor and placed arcs are consistent?

How to fix my old react project not working as expected?

I’m new to react and have just added some regex validation to a jsx file in an existing react project (created about 4 months ago) . After building a new bundle.js file my react project works completely differently. I’m pretty sure the code is correct and hasn’t broken anything. I tried to run the older working version of the project without my changes locally and it still works differently. I think this might be because of build issues. What configurations can I do to make the react app work as expected like it was before?

how can i add inline javascripts to navigation template in Google App Scripts

I am trying to develop a navigational menu being referenced to different pages in my app.
am using Materialize css as a ui and placed the nav codes in a separate file

        <div id="navigation">
    <nav>
      <div class="nav-wrapper blue darken-3">
        <div class="container">
          <a href="#" class="brand-logo">
          <a href="#" class="sidenav-trigger" data-target="sideMobile"> <i class="material-icons">menu</i> </a>      
          <ul class="right hide-on-med-and-down">
            <li>          
              <a href="<?= getbaseUrl(); ?> "  class=" waves-effect waves-light" type="button"  >Incoming Stock</a>
            </li>
            <li><a href="page.html">Components</a></li>
            <li><a href="page.html">Javascript</a></li>
            <li><a href="page.html">Mobile</a></li>
          </ul>

        </div>
      </div>
    </nav>

    <ul class="sidenav  blue lighten-2" id="sideMobile">
      <div class="container">
        <li><a href="page.html">Sass</a></li>
        <li><a href="page.html">Components</a></li>
        <li><a href="page.html">Javascript</a></li>
        <li><a href="page.html">Mobile</a></li>
      </div>
    </ul> 
    </div>

which is being reference in the different pages as

<?!= include("navBar"); ?>

in the <head> part of the code.

function include() is in the serverside code as

return HtmlService.createHtmlOutputFromFile(filename).getContent();
}

in the doGet part of the app, page is being rendered by

return HtmlService.createTemplateFromFile("home").evaluate();

how can i get to write inline codes in the navBar page? when rendered, all javascript are being displayed as encoded html.

thank you in advance

how to respect aside and navbar

im trying to add some text respecting the navbar. But im having some trouble.
can someone help me please with this trouble.

heres codepen:
https://codepen.io/ficiency/pen/OJQRaBy?editors=1100

:root{
    --fondo-color:#181818;
    --items-color:#202020;
    --border-color:#383838;
    --text-color:#e7e7e7;
}
*{
    padding: 0;
    box-sizing: border-box;
    margin: 0;
}
html{
    font-size: 62.5%;
    font-family: sans-serif;
}
body{
    width: 100%;
    height: 100vh;
    background-color: var(--fondo-color);
    position: relative;
}
nav{
    display: flex;
    align-items:center;
    width: 100%;
    padding: 10px 20px;
    background-color: var(--items-color);
    position: absolute;
    border-bottom: 1px solid var(--border-color);
}
nav img{
    margin-left: 20px;
}
nav span i{
    color: #fff;
    font-size: 2.7rem;
    cursor: pointer;
}
aside{
    background-color: var(--items-color);
    width: 260px;
    position: absolute;
    top: 0;
    left: 0;
    bottom:0;
    overflow-y: hidden;
    margin-top: 59px;
    transition: 0.5s;
}
aside:hover{
    overflow-y: auto;
}
.desplegar{
    transform: translateX(-100%);
}
aside::-webkit-scrollbar{
    width: 8px;
}
aside::-webkit-scrollbar-thumb{
    background-color: #909090;
    border-radius: 5px;
}
.container-svg{
    border-bottom: 1px solid var(--border-color);
    padding: 10px 1px;
    color: var(--text-color);
}
.container-svg div{
    display: flex;
    align-items: center;
    width: 100%;
    padding: 10px 20px;
    cursor: pointer;
}
.container-svg div:hover{
    background-color: #303030;
}
.container-svg div span{
    margin-left: 15px;
    font-size: 1.5rem;
    font-weight: 500;
}
h2{
    padding: 10px 20px;
    color: #aaaaaa;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
    <link rel="stylesheet" href="{{ url_for('static', filename='css/inite.css') }}">
    <link href='https://unpkg.com/[email protected]/css/boxicons.min.css' rel='stylesheet'>
</head>
<body>
    <nav>
        <span id="open-close"><i class='bx bx-menu'></i></span>
            <img src="{{ url_for('static', filename='/images/zorro3.png') }}" alt="" width="45" height="40" class="d-inline-block align-text-center" style="margin-left:10px">
   
    </nav>
    <aside id="aside">
        <div class="container-svg">
            <div>
                <svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" fill="#909090" focusable="false" class="style-scope yt-icon" style="pointer-events: none; display: block; width: 25px; height: 25px;"><g class="style-scope yt-icon"><path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8" class="style-scope yt-icon"></path></g></svg>
                <span>Inicio</span>
            </div>
            <div>
                <svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" fill="#909090" focusable="false" class="style-scope yt-icon" style="pointer-events: none; display: block; width: 25px; height:25px;"><g class="style-scope yt-icon"><path d="M11.23 13.08c-.29-.21-.48-.51-.54-.86-.06-.35.02-.71.23-.99.21-.29.51-.48.86-.54.35-.06.7.02.99.23.29.21.48.51.54.86.06.35-.02.71-.23.99a1.327 1.327 0 01-1.08.56c-.28 0-.55-.08-.77-.25zM22 12c0 5.52-4.48 10-10 10S2 17.52 2 12 6.48 2 12 2s10 4.48 10 10zm-3.97-6.03L9.8 9.8l-3.83 8.23 8.23-3.83 3.83-8.23z" class="style-scope yt-icon"></path></g></svg>
                <span>Explorar</span>
            </div>
            <div>
                <svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false" fill="#909090"  class="style-scope yt-icon" style="pointer-events: none; display: inline-block; width:25px; height:25px;"><g class="style-scope yt-icon"><path d="M18.7 8.7H5.3V7h13.4v1.7zm-1.7-5H7v1.6h10V3.7zm3.3 8.3v6.7c0 1-.7 1.6-1.6 1.6H5.3c-1 0-1.6-.7-1.6-1.6V12c0-1 .7-1.7 1.6-1.7h13.4c1 0 1.6.8 1.6 1.7zm-5 3.3l-5-2.7V18l5-2.7z" class="style-scope yt-icon"></path></g></svg>
                <span>Suscripciones</span>
            </div>
        </div>
        <div class="container-svg">
            <div>
                <svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false" fill="#909090" class="style-scope yt-icon" style="pointer-events: none; display: inline-block; width: 25px; height: 25px;"><g class="style-scope yt-icon"><path fill="none" d="M0 0h24v24H0z" class="style-scope yt-icon"></path><path d="M4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6zm16-4H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-8 12.5v-9l6 4.5-6 4.5z" class="style-scope yt-icon"></path></g></svg>
                <span>Biblioteca</span>
            </div>
            <div>
                <svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false" fill="#909090" class="style-scope yt-icon" style="pointer-events: none; display: inline-block; width: 25px; height: 25px;"><g class="style-scope yt-icon"><path d="M11.9 3.75c-4.55 0-8.23 3.7-8.23 8.25H.92l3.57 3.57.04.13 3.7-3.7H5.5c0-3.54 2.87-6.42 6.42-6.42 3.54 0 6.4 2.88 6.4 6.42s-2.86 6.42-6.4 6.42c-1.78 0-3.38-.73-4.54-1.9l-1.3 1.3c1.5 1.5 3.55 2.43 5.83 2.43 4.58 0 8.28-3.7 8.28-8.25 0-4.56-3.7-8.25-8.26-8.25zM11 8.33v4.6l3.92 2.3.66-1.1-3.2-1.9v-3.9H11z" class="style-scope yt-icon"></path></g></svg>
                <span>Historial</span>
            </div>
            <div>
                <svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false" fill="#909090"  class="style-scope yt-icon" style="pointer-events: none; display: inline-block; width:25px; height:25px;"><g class="style-scope yt-icon"><path d="M18.4 5.6v12.8H5.6V5.6h12.8zm0-1.8H5.6a1.8 1.8 0 0 0-1.8 1.8v12.8a1.8 1.8 0 0 0 1.8 1.9h12.8a1.8 1.8 0 0 0 1.9-1.9V5.6a1.8 1.8 0 0 0-1.9-1.8z" class="style-scope yt-icon"></path><path d="M10.2 9v6.5l5-3.2-5-3.2z" class="style-scope yt-icon"></path></g></svg>
                <span>Mis videos</span>
            </div>
            <div>
                <svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false" fill="#909090" class="style-scope yt-icon" style="pointer-events: none; display: inline-block; width: 25px; height:25px;"><g class="style-scope yt-icon"><path d="M12 3.67c-4.58 0-8.33 3.75-8.33 8.33s3.75 8.33 8.33 8.33 8.33-3.75 8.33-8.33S16.58 3.67 12 3.67zm3.5 11.83l-4.33-2.67v-5h1.25v4.34l3.75 2.25-.67 1.08z" class="style-scope yt-icon"></path></g></svg>
                <span>Ver mas tarde</span>
            </div>
            <div>
                <svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false" fill="#909090"  class="style-scope yt-icon" style="pointer-events: none; width:25px; height:25px;"><g class="style-scope yt-icon"><circle cx="6" cy="18" r="2" fill="none" class="style-scope yt-icon"></circle><circle cx="6" cy="6" r="2" fill="none" class="style-scope yt-icon"></circle><path d="M9.64 7.64c.23-.5.36-1.05.36-1.64 0-2.21-1.79-4-4-4S2 3.79 2 6s1.79 4 4 4c.59 0 1.14-.13 1.64-.36L10 12l-2.36 2.36C7.14 14.13 6.59 14 6 14c-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4c0-.59-.13-1.14-.36-1.64L12 14l7 7h3v-1L9.64 7.64zM6 8c-1.1 0-2-.89-2-2s.9-2 2-2 2 .89 2 2-.9 2-2 2zm0 12c-1.1 0-2-.89-2-2s.9-2 2-2 2 .89 2 2-.9 2-2 2zm6-7.5c-.28 0-.5-.22-.5-.5s.22-.5.5-.5.5.22.5.5-.22.5-.5.5zM19 3l-6 6 2 2 7-7V3z" class="style-scope yt-icon"></path></g></svg>
                <span>Tus clips</span>
            </div>
            <div>
                <svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false" fill="#909090" class="style-scope yt-icon" style="pointer-events: none; display: inline-block; width:25px; height:25px;"><g class="style-scope yt-icon"><path d="M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z" class="style-scope yt-icon"></path></g></svg>
                <span>Mostrar mas</span>
            </div>
        </div>
        <div class="container-svg">
            <h2>MÁS DE YOUTUBE</h2>
            <div>
                <svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false" fill="#909090" class="style-scope yt-icon" style="pointer-events: none; display: block; width:25px; height:25px;"><g class="style-scope yt-icon"><path fill-rule="nonzero" d="M21.78 8s-.2-1.37-.8-1.97c-.75-.8-1.6-.8-2-.85C16.2 4.98 12 5 12 5s-4.18-.02-6.97.18c-.4.05-1.24.05-2 .85-.6.6-.8 1.97-.8 1.97s-.2 1.63-.23 3.23v1.7c.03 1.6.23 3.2.23 3.2s.2 1.4.8 2c.76.8 1.75.76 2.2.85 1.57.15 6.6.18 6.77.18 0 0 4.2 0 7-.2.38-.04 1.23-.04 2-.84.6-.6.8-1.98.8-1.98s.2-1.6.2-3.22v-1.7c-.02-1.6-.22-3.22-.22-3.22zm-11.8 7V9.16l5.35 3.03L9.97 15z" class="style-scope yt-icon"></path></g></svg>
                <span>YouTube Premium</span>
            </div>
            <div>
                <svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false"  fill="#909090"  class="style-scope yt-icon" style="pointer-events: none; display: block; width:25px; height:25px;"><g fill-rule="evenodd" class="style-scope yt-icon"><path d="M22,13V8l-5-3l-5,3l0,0L7,5L2,8v5l10,6L22,13z M9,11H7v2H6v-2H4v-1h2V8h1v2h2V11z M15,13 c-0.55,0-1-0.45-1-1s0.45-1,1-1s1,0.45,1,1S15.55,13,15,13z M18,11c-0.55,0-1-0.45-1-1s0.45-1,1-1s1,0.45,1,1S18.55,11,18,11z" class="style-scope yt-icon"></path></g></svg>
                <span>Videojuegos</span>
            </div>
            <div>
                <svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false" fill="#909090"  class="style-scope yt-icon" style="pointer-events: none; display: block; width:25px; height:25px;"><g class="style-scope yt-icon"><path d="M16.94 6.91l-1.41 1.45c.9.94 1.46 2.22 1.46 3.64s-.56 2.71-1.46 3.64l1.41 1.45c1.27-1.31 2.05-3.11 2.05-5.09s-.78-3.79-2.05-5.09zM19.77 4l-1.41 1.45C19.98 7.13 21 9.44 21 12.01c0 2.57-1.01 4.88-2.64 6.54l1.4 1.45c2.01-2.04 3.24-4.87 3.24-7.99 0-3.13-1.23-5.96-3.23-8.01zM7.06 6.91c-1.27 1.3-2.05 3.1-2.05 5.09s.78 3.79 2.05 5.09l1.41-1.45c-.9-.94-1.46-2.22-1.46-3.64s.56-2.71 1.46-3.64L7.06 6.91zM5.64 5.45L4.24 4C2.23 6.04 1 8.87 1 11.99c0 3.13 1.23 5.96 3.23 8.01l1.41-1.45C4.02 16.87 3 14.56 3 11.99s1.01-4.88 2.64-6.54z" class="style-scope yt-icon"></path><circle cx="12" cy="12" r="3" class="style-scope yt-icon"></circle></g></svg>
                <span>Directo</span>
            </div>
            <div>
                <svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" fill="#909090" focusable="false" class="style-scope yt-icon" style="pointer-events: none; display: block; width:25px; height:25px;"><g class="style-scope yt-icon"><path d="M9 21c0 .5.4 1 1 1h4c.6 0 1-.5 1-1v-1H9v1zm3-19C8.1 2 5 5.1 5 9c0 2.4 1.2 4.5 3 5.7V17c0 .5.4 1 1 1h6c.6 0 1-.5 1-1v-2.3c1.8-1.3 3-3.4 3-5.7 0-3.9-3.1-7-7-7z" class="style-scope yt-icon"></path></g></svg>
                <span>Aprendizaje</span>
            </div>
            <div>
                <svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" fill="#909090"  focusable="false" class="style-scope yt-icon" style="pointer-events: none; display: block; width: 25px; height: 25px;"><g class="style-scope yt-icon"><path d="M6.85 7.76V6.18H1v2.88c0 2.35 1.9 4.26 4.26 4.26h1.59v-1.59H5.4a2.81 2.81 0 01-2.81-2.8V7.75h4.26zM17.15 7.76V6.18H23v2.88c0 2.35-1.9 4.26-4.26 4.26h-1.59v-1.59h1.45a2.81 2.81 0 002.81-2.8V7.75h-4.26z" class="style-scope yt-icon"></path><path d="M12 17.29a6.87 6.87 0 01-6.87-6.87V3h13.74v7.42c0 3.8-3.07 6.87-6.87 6.87z" class="style-scope yt-icon"></path><path d="M12 17.29V3h6.87v7.42c0 3.8-3.07 6.87-6.87 6.87zM12 17.29l4.13 2.38H7.88L12 17.3zM16.13 19.67H7.88v2.38h8.25v-2.38z" class="style-scope yt-icon"></path></g></svg>
                <span>Deportes</span>
            </div>
        </div>
    </aside>
    <div class="container-fluid">
        <p style="padding:20px;color:white; ">
        Dr.A.P.J Abdul Kalam was known as one the most  famous personality in the India.  His full name was Avul Pakir Jainulabdeen Abdul Kalam. His whole life journey comes in between  15 october 1931 – 27 july 2015 . .In this time he was worked as aerospace scientist .  Rameswaram ,Tamil Nadu was his birthplace. As well as he was completed his education in physics and aerospace engineering from Tamilnadu state itself. He was provide service to the nation as being  11th president of India from 2002 to 2007.  He almost spend  4 decades of service as being scientist and science administrator , majorly he was active participants at the Defence Research and Development Organisation (DRDO) and in  most famous organization of India i.e  and Indian Space Research Organization (ISRO).  Due to his active participation in those  organization  and had part of India’s military missile development  he was known as Missile Man of India. He played very important role in nuclear test which is taken by India for Pokharan -2 nuclear test in the year 1998.<br> He was well known personality in all reputed fields like education, aerospace, military, public service and into the writing. He died on 27 July 2015, aged 83</p>
    </div>
</body>
 <script>
    const $openClose = document.getElementById("open-close"),
        $aside = document.getElementById("aside");

    $openClose.addEventListener("click",()=>{
        $aside.classList.toggle("desplegar")
        })
</script>
</html>

My goal is that i can see < p > tag down the navbar, i have tried assigning the navbar a position:absolute property but still no result.

I know i can add a margin-top to < p > tag but when i do this, the navbar and aside tag also come down. why do u guys think this might be happening?

How do I return the final discounted price instead of the discounted amount off?

I am creating a method that takes a percent as a parameter and decreases the price by that percent.

public void lowerPriceBy(double percent){
        price = price/100*percent;
        
    }

My question is how to I get my method to return the final discounted price of the car instead of the discounted amount?
For example if the car costs $10,000 and the percentage is 5% I want to return Price = $9500 but im only getting Price = $500 when I do the calculations.

Any help is appreciated.

How to include a string in my website url? [duplicate]

I created a shop and the url is like:
https://myshop.com

But my client asked me to add respective salers’ id into the url so that they can do some analyses, so it would look like:
https://saler001.myshop.com

I don’t know where should I start to do this trick, maybe something in the DNS settings? Currently I’ve suggested them using url query string, but they don’t accept.

btw, this shop is on Shopify.

JQ validation error appear on select value change

The form required the user to input phone number if its not employee, I have done this part. How to make the validation error appear on select value change? For example if the user pick employee, the form will not show “phone number is required” but if the user changed the select option to support, the form will show “phone number required” without pressing the submit button?

Here the code snippet:

    <body>
    <div class="main-block">


      <form method="POST" id="new_form">
        <h1>Contact Us</h1>
        <div class="info">
        <select name="usertype" id="user_type">
          <option value="" disabled selected>User Type</option>
          <option value="Employee">Employee</option>
          <option value="Customer">Customer</option>
          <option value="Support">Support</option>
        </select>
        </div>
          <input id = "fname" type="text" name="name" placeholder="Full name">
          <input id="email" type="text" name="email" placeholder="Email">
          <input id="phone_number" type="text" name="phoneNumber" placeholder="Phone number">
        <button id="submit_button" type="submit">Submit</button>
       </div>
      </form>
    </div>
  </body>


  <script>
      $(function() {
        $("#new_form").validate({
              rules: {
                usertype: "required",
                name: "required",
                phoneNumber: {
                    required: function() {
                        if($("#user_type").val() == 'Employee'){
                          return false;
                        }else {
                          return true;
                        }
                    }
                },
                email: {
                  required: true,
                  email: true
                }
              },
              messages: {
                usertype: "User Type is required",
                name: "Name is required",
                email: {
                  required: "Email is required",
                  email: "Your email address must be in the format of [email protected]"
                },
                phoneNumber: "Phone number is required"
             }
        });
            $('#new_form').on('submit', function(e) {
                var data = $("#new_form :input").serializeArray();
                console.log(data);
            });
            
        });
  </script>