Attempting to use a “Next” button to change active li class in navbar

I know its more than likely been asked before but I’ve searched all over the place trying to figure this out. I already have JS that will change the navbar li class to active on navbar click as shown below, that works fine. But I also have a “next” button that should also do the same thing on click, change the li class of the nav bar to active. The button is set to hide the current tab, and show the next tab so the users wont have to keep scrolling up to click the next tab. No matter what i’ve done i cant get this to work.

// Add active class to the current button (highlight it)
var header = document.getElementById("navsub");
var btns = header.getElementsByClassName("nav-item");
for (var i = 0; i < btns.length; i++) {
  btns[i].addEventListener("click", function() {
  var current = document.getElementsByClassName("active");
  current[0].className = current[0].className.replace(" active", "");
  this.className += " active";
  });
}

and Below is the associated html

<ul id="navsub" class="navsub">


            <li class="nav-item active"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs1">Contact Info</a></li>
            <li class="nav-item"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs2">Case</a></li>
            <li class="nav-item"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs3">Processor</a></li>
            <li class="nav-item"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs4">Cooling</a></li>               
            <li class="nav-item"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs5">RAM</a></li>
            <li class="nav-item"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs6">Storage</a></li>
            <li class="nav-item"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs7">Power Supply</a></li>
            <li class="nav-item"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs8">Fans, Lighting & Sleeving</a></li>
            <li class="nav-item"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs9">Accessories</a></li>
            <li class="nav-item"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs10">Graphics Card</a></li>
        </ul>   

Uncaught TypeError: _firebase__WEBPACK_IMPORTED_MODULE_2__.default.collection is not a function

I’m working on this newsletter which takes the user’s full names, email, and phone numbers.
Every time I try to submit the info I get this error ->

Uncaught TypeError: _firebase__WEBPACK_IMPORTED_MODULE_2__.default.collection is not a function
    at submit (Newsletter.jsx:13:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:4157:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:4206:1)
    at invokeGuardedCallback (react-dom.development.js:4270:1)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4284:1)
    at executeDispatch (react-dom.development.js:9011:1)
    at processDispatchQueueItemsInOrder (react-dom.development.js:9043:1)
    at processDispatchQueue (react-dom.development.js:9056:1)
    at dispatchEventsForPlugins (react-dom.development.js:9067:1)
    at react-dom.development.js:9258:1

This is my code ->

firebasse.js

import { initializeApp } from "firebase/app";
import { getFirestore} from "firebase/firestore";

const firebaseConfig = {
  ...
};

const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
export default db;

Newsletter.jsx

import { React, useState } from "react";
import "./newsletter.css";
import db from "../../firebase";

const Newsletter = () => {
  const [userName, setUserName] = useState("");
  const [userEmail, setUserEmail] = useState("");
  const [userPhoneNumber, setUserPhoneNumber] = useState("");

  const submit = (e) => {
    e.preventDefault();
    db.collection("Users").add({
      name: userName,
      email: userEmail,
      phoneNumber: userPhoneNumber,
    });
  
    setUserName("");
    setUserEmail("");
    setUserPhoneNumber("");
  };

one of the input field

          <div className="newsletterInput">
            <input
              type="name"
              onChange={(e) => setUserName(e.target.value)}
              placeholder="Full Name"
              required
            />
          </div>

OneCall API call is throwing an error when calling API for UV index

OneCall API call is throwing an error when calling API for UV index. I’m trying to set the api call to call the info for the city the user inputs into the field to return UV index data. It works fine in my call for the data without the UV index but onecall doesn’t give that info on that call and has to be done with actual lat and long in the call. Is there a way to do this with my cityName variable that works in the other call?

// this is how onecall shows the call should look but i dont have a set lat and lon because its based on the city input from the user  https://api.openweathermap.org/data/2.5/onecall?lat={lat}&lon={lon}&exclude={part}&appid={API key} 


//this api call gets the data for the city correctly but doesn't give uv index
function getApi(cityName) {
    var requestUrl = "https://api.openweathermap.org/data/2.5/forecast?q=" + cityName + "&current.uvi&units=imperial&appid=" + apiKey;

    fetch(requestUrl)
        .then(function (response) {
            return response.json();
        })
        .then(function (data) {
            console.log(data);


function getCity() {
    // event.preventDefault();
    var city = document.getElementById('city').value.trim();

//this call throws the error 
function uvIndex(cityName) {
    let apiUrl = "https://api.openweathermap.org/data/2.5/onecall?lat=" + cityName + "&units=imperial&appid=" + apiKey; ""
    fetch(apiUrl)
        .then(function (response) {
            return response.json();
           
        })
        .then(function (data) {
            let uv = data.current.uvi;
            console.log(uv);
        });
<div class="card-body">
                    <input type="text" class="form-control form-control-lg" id="city" placeholder="Enter City Here">
                    <button onclick="getCity()" class="btn btn-primary my-2" id="search">Search <i
                            class="fas fa-search"></i></button></div>

How do I make my If Statement not jump to else?

My java if statement is not working as expected. When the end user answers the question in either yes or no, I want that answer to drive the output from the if/else statement. However, no matter what the answer is, the code jumps to the else piece. What am I doing wrong?

public void door() {
    
    Scanner keyboard = new Scanner(System.in);
    System.out.print("Is the mailbox door open (yes or no)?");
    String door = keyboard.next();
    this.door = door.toUpperCase();
    
    this.door = "YES";
    this.door = "NO";
    
    String open = "You should close the mailbox door!";
    String close = "The mailbox door is closed.";
    
    if (this.door == "YES") {
        System.out.println(open);
    }
        else
        System.out.println(close);
    
}

how to filter in firebase using javascript?

below is my javascript code snippet, it responds showing all admin databases,taufik,nanarsih,,,I want to get the database value with admin key, how do I do that?

<script type="module">
// Import the functions you need from the SDKs you need
import {
    initializeApp
} from "https://www.gstatic.com/firebasejs/9.6.11/firebase-app.js";
import {
    getAnalytics
} from "https://www.gstatic.com/firebasejs/9.6.11/firebase-analytics.js";
import {
    getDatabase,
    ref,
    onValue,
    equalTo
} from "https://cdnjs.cloudflare.com/ajax/libs/firebase/9.6.11/firebase-database.min.js";

// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
    apiKey: "123",
    authDomain: "123",
    databaseURL: "123",
    projectId: "123",
    storageBucket: "123",
    messagingSenderId: "123",
    appId: "123",
    measurementId: "123"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const db = getDatabase(app);

onValue(ref(db), (snapshot) => {
    const data = snapshot.val();
    console.log(data);
});

In firebase

this is the response in the console log:

{admin: 123, nanarsih: 123, taufik: 123}

How to directly change TranslateX from one position to another smoothly?

I am facing this issue from a long time, Finally I managed to make a demo example of my problem. I am trying to make a infinite image scroll view. So when we point our mouse down and try to scroll to the right position, after change is more than 40%, I want to transform directly from translateX to the last item transform value (-400px), but I am having a transition: 400ms ease on the container so whenever I try to change TranslateX value from 0 to -400 when mouse is moving towards the right side (back from the 1st image), it gives a full transition effect of travelling from 0 to -400, and to solve this issue, I try to remove the transition after the change hits 40% and then change the translateX value, it works, but its giving a sudden stop effect when I remove the transition and update the translateX value. I want it to be smooth and transition and smoothly change translateX value directly without travelling.
Please anyone help me, I am facing this issue from a long time, :- https://jsfiddle.net/4nj6cszk/2/

const modal_images_main_inner = document.querySelector('.modal-images-main-inner');
    const modal_main_image_wrapper = document.querySelector('.modal-main-image-wrapper');
    const modal_main_carousel = document.getElementById('modal-main-carousel');
    
    const modal_slide_images = document.querySelectorAll('.modal-show-image');
    //const verttest = document.getElementById('verttest');

    const modalconfig = {
        modalindividualItem: '.modal-show-image', // class of individual item
        modalcarouselWidth: modal_images_main_inner.offsetWidth, // in px
        modalcarouselId: '#modal-images-main-inner-container',  // carousel selector
        modalcarouselHolderId: '#modal-main-carousel', // carousel should be <div id="carouselId"><div id="carouselHolderId">{items}</div></div>  
    }

    

    let modal_mousedown = false;
    let modal_movement = false;
    let modal_initialPosition = 0;
    let modal_selectedItem;
    let modal_currentDelta = 0;

    let modalupchange;
    let elementIndex;
    let modalupDelta;

    document.querySelectorAll(modalconfig.modalcarouselId).forEach(function(item) {
        item.addEventListener('pointerdown', function(e) {
            const modal_images_parent = e.target.closest('.modal-main-image-wrapper').parentElement;
            const imagesIndex = modal_images_parent.parentElement.dataset.index;
            elementIndex = imagesIndex;
            modal_mousedown = true;
            modal_selectedItem = item;
            modal_initialPosition = e.pageX;
            modal_currentDelta = parseFloat(item.querySelector(modalconfig.modalcarouselHolderId).style.transform.split('translateX(')[1]) || 0;
            
            modalupDelta = modal_currentDelta;
        });     
    });

    const modalscrollCarousel = function(change, currentDelta, selectedItem) {
   
        let newDelta = currentDelta + change;
        const diff = newDelta - (currentDelta);
        const diffpercent = (diff / modalconfig.modalcarouselWidth) * 100; 
        const newdiffpercent = currentDelta + diffpercent;  
        
        
        if(newdiffpercent <= 0) {       
            if(newdiffpercent > 0) {
                const lastItemLeftValue = parseFloat(modal_slide_images[modal_slide_images.length - 1].style.left);
                if(lastItemLeftValue <= -100) {
                    modal_slide_images[modal_slide_images.length - 1].style.left = `${parseInt(modal_slide_images[modal_slide_images.length - 1].dataset.index) * 100}%`;
                }
            }
            if(selectedItem.querySelector(modalconfig.modalcarouselHolderId).classList.contains('modal-no-transition')) {
                selectedItem.querySelector(modalconfig.modalcarouselHolderId).classList.remove('modal-no-transition');
            }

            selectedItem.querySelector(modalconfig.modalcarouselHolderId).style.transform = `translateX(${newdiffpercent}%)`;
           
        } else {
             if(newdiffpercent >= 0) {
                 if(elementIndex == 0) { 
                    const fupTransform = parseFloat(modal_slide_images[2].style.left);
                    
                    selectedItem.querySelector(modalconfig.modalcarouselHolderId).style.transform = `translateX(${newdiffpercent}%)`;
                    modal_slide_images[modal_slide_images.length - 1].style.left = `-100%`;
                    if(newdiffpercent >= 40) {
                       
                        const lastItemValue = modal_slide_images[modal_slide_images.length - 1].dataset.index;
                        
                        
                        modal_slide_images[modal_slide_images.length - 1].style.left = `${parseInt(modal_slide_images[modal_slide_images.length - 1].dataset.index) * 100}%`;
                        modal_slide_images[0].style.left = `${(parseInt(modal_slide_images[modal_slide_images.length - 1].dataset.index) + 1) * 100}%`;
                        
                        selectedItem.querySelector(modalconfig.modalcarouselHolderId).classList.add('modal-no-transition');
                        selectedItem.querySelector(modalconfig.modalcarouselHolderId).style.transform = `translateX(${-(lastItemValue * 100) - (100 - newdiffpercent)}%)`;
                        window.requestAnimationFrame(_ => { selectedItem.querySelector(modalconfig.modalcarouselHolderId).classList.remove("transition-no"); });
                        
                        const loopLastTransform = parseFloat(modal_main_carousel.style.transform.split('translateX(')[1]);

                       
                 }
                 else {
                    selectedItem.querySelector(modalconfig.modalcarouselHolderId).style.transform = `translateX(${newdiffpercent}%)`;
                 }
                
            }
        }
    }
   }


    document.body.addEventListener('pointermove', function(e) {
        if(modal_mousedown == true && typeof modal_selectedItem !== "undefined") {
            let change = -(modal_initialPosition - e.pageX);
            modalupchange = change;
            
            modalscrollCarousel(change, modal_currentDelta, document.body);
            document.querySelectorAll(`${modalconfig.modalcarouselId} img`).forEach(function(item) {
                item.style.pointerEvents = 'none';
            });
            modal_movement = true;
        }
    });
    
    ['pointerup', 'mouseleave'].forEach(function(item) {
        document.body.addEventListener(item, function(e) {
            modal_selectedItem = undefined;
            modal_movement = false;
            document.querySelectorAll(`${modalconfig.modalcarouselId} img`).forEach(function(item) {
                item.style.pointerEvents = 'all';
            });           
        });
    });

    
.modal-images-main {
    position: relative;
    flex-grow: 1;
    flex-shrink: 1;
    flex-basis: auto;
}

.modal-images-main-inner {
    position: relative;
    overflow: hidden;
}
.modal-images-main-effect {
    
    
    border-radius: 24px;
}

.modal-show-image {
    width: 100%;
    overflow: hidden;
    position: absolute;
}

.modal-main-image-wrap {
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
}

.modal-main-image-wrapper {
    height: 0; 
    padding-bottom: 100.0%; 
    overflow: hidden; 
    background: #f1f1f1;
}

.modal-no-transition {
    transition: none !important;
}

.modal-images-main-carousel {
  width: 100%;
    height: 100%;
    position: absolute;
    transition: transform 400ms ease-out 0s;
}
<div class="modal-images-main">
                                                        <div id="modal-images-main-inner-container" class="modal-images-main-inner modal-images-main-effect" style="height: 440px; touch-action: pan-y;">
                                                            <div style="left: 0px; transform: translateX(0%);" id="modal-main-carousel" class="modal-images-main-carousel">
                                                                <div style="position: absolute; left: 0%;" data-index="0" class="modal-show-image">
                                                                    <div style="position: relative;">
                                                                        <div class="modal-main-image-wrapper">
                                                                            <img class="modal-main-image-wrap" data-sizes="auto" src="https://www.w3schools.com/howto/img_lights.jpg" style="pointer-events: none;">
                                                                        </div> 
                                                                    </div>
                                                                </div>
                                                                <div style="position: absolute; left: 100%;" data-index="1" class="modal-show-image">
                                                                    <div style="position: relative;">
                                                                        <div class="modal-main-image-wrapper">
                                                                            <img class="modal-main-image-wrap" data-sizes="auto" src="https://www.w3schools.com/html/pic_trulli.jpg" style="pointer-events: none;">
                                                                        </div> 
                                                                    </div>
                                                                </div>
                                                                <div style="position: absolute; left: 200%;" data-index="2" class="modal-show-image">
                                                                    <div style="position: relative;">
                                                                        <div class="modal-main-image-wrapper">
                                                                            <img class="modal-main-image-wrap" data-sizes="auto" src="https://www.w3schools.com/html/img_chania.jpg" style="pointer-events: none;">
                                                                        </div> 
                                                                    </div>
                                                                </div>
                                                                <div style="position: absolute; left: 300%;" data-index="3" class="modal-show-image">
                                                                    <div style="position: relative;">
                                                                        <div class="modal-main-image-wrapper">
                                                                            <img class="modal-main-image-wrap" data-sizes="auto" src="https://www.w3schools.com/howto/img_snow.jpg
" style="pointer-events: none;">
                                                                        </div> 
                                                                    </div>
                                                                </div>
                                                                <div style="position: absolute; left: 400%;" data-index="4" class="modal-show-image">
                                                                    <div style="position: relative;">
                                                                        <div class="modal-main-image-wrapper">
                                                                            <img class="modal-main-image-wrap" data-sizes="auto" src="https://www.w3schools.com/howto/img_mountains.jpg" style="pointer-events: none;">
                                                                        </div> 
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>

Enter data into object with specific format

for privacy I explain my problem with simple example I want to save information of employee in an Object , In This Format:

const infoList = {
    "01": {
        "name": "alex",
        "family": "tirko",
        "address": {
            "city": "berlin",
            "street": "tomas",
              }
    },
    "02": {
        "name": "sara",
        "family": "johansson",
        "address": {
            "city": "denmark",
            "street": "vigerslev",
           
        }
    },
}

my question is how to get from input this data and then Create object with specific format ?

I mean create “o3” and “04” and so on with same format and should get all of elements from input
Get data in while until user cancel and close prompt.
if user entered incomplete data should not save data.

any solution would be my appreciated

Get path of exact dependency from node_modules package

How can I get path of exact dependency from a certain node_modules package?

For example:

|- node_modules/
   |- [email protected]/
      |- package.json
   |- package-b/
      |- node_modules/
         |- [email protected]/
      |- package.json
   |- package-c/
      |- node_modules/
         |- [email protected]/
      |- package.json

Is there a way I can get the location of package-a that package-b depends on only by reading node_modules/package-b/package.json? In this case, the output should be node_modules/package-b/node_modules/package-a/package.json.

How to find trailing/leading ones/zeroes, count ones/zeroes, and reverse bits in JavaScript without resorting to string manipulation?

I searched around on the web for a while on this one, but haven’t found anything. How do you translate these functions into the optimal bit manipulations?

// this one is optimal
function nextPowerOfTwo (n) {
  if (n === 0) return 1
  n--
  n |= n >> 1
  n |= n >> 2
  n |= n >> 4
  n |= n >> 8
  n |= n >> 16
  return n+1
}

// this is for bytes, perhaps, which I think is optimal
function countNumOnesInByte(byte) {
  return  ((byte>>3)&1)+((byte>>2)&1)+((byte>>1)&1)+(byte&1)
}

function countNumZeroesInByte(byte) {
  return countNumOnesInByte(~byte)
}

// JS has a built in method for this one.
function countLeadingZeroes(uint32) {
  return Math.clz32(uint32)
}

function countLeadingOnes(int) {
  const chars = int.toString(2).split('')
  let i = 0
  while (chars[i] === '1') {
    i++
  }
  return i
}

// this one is pretty standard.
function countOnes(n) {
  n = n - ((n >> 1) & 0x55555555)
  n = (n & 0x33333333) + ((n >> 2) & 0x33333333)
  return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24
}

function countZeroes(int) {
  return countOnes(~int)
}

function countTrailingOnes(int) {
  const chars = int.toString(2).split('').reverse()
  let i = 0
  while (chars[i] === '1') {
    i++
  }
  return i
}

function countTrailingZeroes(int) {
  const chars = int.toString(2).split('').reverse()
  let i = 0
  while (chars[i] === '0') {
    i++
  }
  return i
}

function reverseBits(int) {
  parseInt(int.toString(2).split('').reverse().join(''), 2)
}

Basically trying to finish this list and use only bit manipulation to calculate it.

How to dynamically add table data and fetch them and store it array

I like to dynamically add table elements with respect to input ‘table_nos‘ and fetch the data from the table cells and store them in array. I tried creating one table element first and tried cloning the initial one according to the ‘table_nos‘ on document ready function. In order to fetch values, I replaced the ids of cloned table with dynamic value of “table” + Index. I tried the following code, but it didn’t work.

Correct me if I am wrong.
Thanks in advance.

<body class="nl" style="display: block; margin: 0px;">
   <div class="sidenav"> </div>
   <div class="topnav"> </div>
   <script type="text/javascript" 
         src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> </script> 
          <script src="repeat.min.js"></script>
         <div id="container">
         <div class="row triple">
         <div class="column-3 left">
          <h3 lang = "nl" style="color:black;margin-left:25px;font-family:Helvetica Neue, 
           Arial, Sans-Serif;">Select the client name to the available policy</h3>
     </div>
  </div>
 </div>
 <hr r="">
<script language="javascript" type="text/javascript">
  $(document).ready(function(){
  var linebreak = document.createElement("br");
  var Index = 0;
   $('#repeat').append(linebreak);
   for(var i=1 ;i< table_nos; i++)
   {
      var $temp = $('#repeat_table').clone().attr("id","table" + Index);
       $('#repeat').append($temp);
       $('#repeat').append(linebreak);
      Index++;
   }  
  });
 </script>
  <form style="margin-left:80px">
   <br>
  <div id= "repeat">
  <table id = "repeat_table" style = "width: 70%" >
  <tr class = "repeat-row">
  <td style = "width: 30%">
  <label lang= "nl" for="Client Name" style="color:Grey;font-size: 0.92rem;font-family:Helvetica Neue, Arial, sans-serif">Client Name</label> 
  <br><br> 
  <select id="Client Name" style="width:66.5%" name="Client Name">
     <option></option>
     <option value="Client1">Client1</option>           
    <option value="Client2" >Client2</option>   
    <option value="Client3" >Client3</option>
    <option value="Client4" >Client4</option>
  </select>
   </td>
  <br><br>
  <td style= "width:40%">
  <label for="policy" style="color:Grey;font-size: 0.92rem;font-family:Helvetica Neue, Arial, sans-serif" class="required">Policy</label><br><br> 
  <select id="policy" style="width:50%" name="policy">
     <option></option>
     <option value="Gold">Gold</option>             
    <option value="Platinum" >Platinum</option>     
    <option value="Diamond" >Diamond</option>
  </select>
   </td>
  </tr>
  </table>
    </div>
  <div style="position:fixed;bottom:5px;right:10px; z-index:999"> 
  <button lang="nl" style="margin-right:16px" font: "400 13.3333px Arial" class="myButton" onclick="myJavascriptFunction()">Register</button> 
  <button lang="nl" style="margin-right:16px" font: "400 13.3333px Arial" class="cancelButton" onclick="window.top.close()">Close</button>
  </div>
  <div id="cover-spin">
  </div>
  <script language="javascript" type="text/javascript">
  $(function() { $('#toggle-event').change( function()
  { 
  document.body.className = $(this).data($(this).prop("checked").toString());
  });
  });
  </script>
  </form> 
  <script> 
  function myJavascriptFunction() 
  { 
   var client=new XMLHttpRequest(); 
   var clientnameselect=document.getElementById("clientname"); 
   var clientname=clientnameselect.options[clientnameselect.selectedIndex].value; 
   var UniqueKey=document.getElementById("UniqueKey"); 
   $("#cover-spin").show(0);
   var clientname = [""];
   var policy = [""];
    var Initial_tds = document.getElementById("repeat_table").querySelectorAll('tr.repeat-row td');
    var Initial_policy = Initial_tds.getElementById("policy").find(':selected').value;
    var Initial_clientName = Initial_tds.getElementById("Client 
    Name").find(':selected').value;
    clientname += Initial_clientName + ",";
     policy += Initial_policy + ",";

   for (var j=0 ; j < table_nos - 1 ; j++)
   {
    var tds = document.getElementById("table" + j).querySelectorAll('tr.repeat-row td');
    var repeat_policy = tds.getElementById("policy").find(':selected').value;
    var repeat_clientName = tds.getElementById("Client Name").find(':selected').value;
    clientname += repeat_clientName + ",";
    policy += repeat_policy + ",";
    }
    console.log(clientname);
    console.log(policy);
   }
   </script>
   </body>

I’m working using google chart, but I’m getting an error. can you help me?

I’m working using google chart, but I’m getting an error.I’ve also seen tutorials on youtube but the method is different so it makes me dizzy. can you guys help me?

Error Mesagges : All series on a given axis must be of the same data type

      function drawVisualization() {
        var data = google.visualization.arrayToDataTable([
          ['PELAYANAN', 'PUAS', 'CUKUP', 'KURANG'],
        <?php 
            if(mysqli_num_rows($result)> 0){
                while($row = mysqli_fetch_array($result)){
                    echo "['".$row['id_pl']."', '".$row['puas']."', '".$row['cukup']."', ['".$row['kurang']."' ]],";
                }
            }
        ?>
        ]);

modal pop up with ejs and express

so first I’m very new to backend and maybe a little confused and I have a project so my confusion is how to connect this

modal.ejs

<div class="modal fade text-black" id="Modal" tabindex="-1" aria-labelledby="ModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content position-relative">
            <div class="modal-body">
                <button type="button"
                    class="btn-close position-absolute top-50 end-0 translate-middle btn-danger rounded-circle"
                    data-bs-dismiss="modal" aria-label="Close"></button>
                <% if(true) { %>
                    data accepted
                <% }else{ %>
                    data rejected
                <% } %>
            </div>
        </div>
    </div>
</div>

index.html part form

<form class="col-lg-4 col-lg-offset-4 form-inline justify-content-center" action="/" method="post">
            <input class="form-control mt-2" id="input" type="text" placeholder="Name of company" name="companyName">
            <input class="form-control mt-3" id="input" type="search" placeholder="https://www.company.com/" name="website">    
            <button type="submit" id="button" class="btn btn-primary mt-4 px-4" data-bs-toggle="modal" data-bs-target="#Modal">Check</button>
        </form>
    </div>

so this has worked, but the pop up doesn’t appear, instead a new page appears

app.js

app.post("/", function (req, res) {
  const url = {
    name: req.body.companyName,
    link: req.body.website,
  };

  Url.findOne({ website: url.link }, function (err, foundCompany) {
    if (foundCompany) {
      console.log("found in db");
      // res.redirect("/accepted");
      res.render("modal");
    } else {
      const newUrl = new Url({
        name: url.name,
        website: url.link,
      });

      newUrl.save();

      console.log("not found in db");
      // res.redirect("/notaccepted");
    }
  });
});

and how to make on the server showing modal pop up as a result from check database
if found data => data found
else => data not found

Hackerrank Mini-Max Sum – Doesn’t pass test case

I am working on Hackerrank challenge Mini-Max Sum:

Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers.

Example

arr = [1, 3, 5, 7, 9]

The minimum sum is 1 + 3 + 5 + 7 = 16 and the maximum sum is 3 + 5 + 7 + 9 = 24.

The function prints

16 24

I submitted the below code, but it doesn’t pass one sample test case. Is there anything wrong in my code?

function miniMaxSum(arr) {
    let set = [...new Set(arr)];
    const MIN = set.filter((num) => num !== Math.max(...set)).reduce((sum, num) => sum + num);
    const MAX = set.filter((num) => num !== Math.min(...set)).reduce((sum, num) => sum + num);
    console.log(MIN + ' ' + MAX);
}

The error is a “Runtime Error”