How to make a function only fire when 3 buttons are clicked in Vanilla Javascript?

I couldn’t figure this out or find anything on this on the web.
Basically how would you write code for this:
I have 3 buttons, and I need to click all of them before the function fires.
I know how to have each button do the same thing, but I want it so I have to click all 3 for it to do anything.

If you could give me any example code of this I can find a way to implement it into my project.

If you need me to elaborate let me know.
Thanks!

Is there a way to quickly add a class to a pre-existing element in VSCode? (with Emmet Notation)

When you want to create a div with a class already applied, you can just type div.foo and VSCode will change it to be <div class="foo"></div>, but what if you want to add a class or id to an already existing element?

E.g you already have a div <div></div>, but you want to add a class called bar to it, to make it <div class="bar"></div>

Is there any way you can do this with Emmet notation, VSCode, or some other extension?

React: How to redirect to new route (different id) from same route?

In react-router, we cannot push the same route in useHisotry() and cause a re-render. E.g., if component App is showing on route https://localhost:3000 and I click the button Click Me!, it won’t cause a re-render:

function App() {
   const history = useHistory();
   return (
      <button onClick={() => {history.push('/')}}> Click Me! </button>
   )
}

I want to achieve similar functionality, but I am unsure about the approach or what I am missing.

My current route looks like this: https://localhost:3000/user/1

I want to go to user/2 by clicking a button.

My code looks like the below:

<Route exact path="/user/:userId" component={User} />

function User() {
   const history = useHistory();
   return (
      <button onClick={() => {history.push('/user/2')}}> Click Me! </button>
   )
}

The above code changes the route but doesn’t re-render the component. How can I fix this issue?

Thanks

My ReactJS app in Chrome Task Manager CPU is High but Windows Task Manage is low. Why?

I’m using Reactjs to create a dashboard site that has about 15 different data grids that update every 500ms via websockets with a large amount of data virtualized per grid (7k records). Performance seems great on multiple lower / higher end machines (tested 5 different pc’s and 1 mac) and the app also performs well in firefox safari and Edge.

My concern is that when I open Chrome’s task manager it says CPU usage is anywhere from 50 to 120; however, if I look at the windows task manager, CPU usage for chrome is only at 4-5%. It would seem that the values in the chrome task manager don’t correlate to the Windows Task Manager.

On chromes dev site at https://developer.chrome.com/docs/extensions/reference/processes/ it says “The most recent measurement of the process’s CPU usage, expressed as the percentage of a single CPU core used in total, by all of the process’s threads. This gives a value from zero to CpuInfo.numOfProcessors*100, which can exceed 100% in multi-threaded processes. Only available when receiving the object as part of a callback from onUpdated or onUpdatedWithMemory.”

Do I need to worry if chrome says my reactjs app is 50-120 CPU? What is it exactly that the chrome task manager measures in regards to CPU usage and how are these values calculated, I don’t understand the above linked text? Is there a better way to measure true CPU usage of my reactjs app?

Thank you.

Authorization Error Error 401: deleted_client The OAuth client was deleted

I am working on a nextjs project and using next auth for my authentication , i keep getting this error once i click on here . on the click of a button , i want it to redirect me to the sign up page , where i click my google accont . then it redirects me back to the page

Authorization Error
Error 401: deleted_client
The OAuth client was deleted.

i dont know what to do to solve it , i just want to sign my users in . I am also using firebase in conjuction with nextjs

How can I get the access of a const inside my function?

How can I grant access to my const to be used inside a function? In this case I want to access my const catName inside my function fetchListings. I’m getting this error:

Question Updated:

ReferenceError: catName is not defined

<script context="module">

const fetchListings = async () => {

        try {
            // get reference to listings collection
            const listingsRef = collection(db, 'listings');
            // create a query to get all listings
            const q = query(
                listingsRef,
                where('type', '==', catName),
                orderBy(timestamp, 'desc'),
                limit(10)
            );
            // execute query
            const querySnap = await getDocs(q);

            let lists = [];

            querySnap.forEach((doc) => {
                console.log(doc);
            });

        } catch (error) {
            console.log(error);
        }
    };
    fetchListings();
</script>

<script>
    import { page } from '$app/stores';
    // export the const catName to the function above
    export const catName = $page.params.catName;
</script>

Hi {catName}!

Ensuring passwords input in form match using javascript

I have coded an HTML form and need to ensure that a user inputs a password in the Password field and repeats the same password in the Confirm Password field. To ensure they are equal, I have used a javascript function to make it possible. Also, I have disabled the Register button, and need to ensure it is only enabled if and only if the values entered in the two password boxes are equal. Everything works fine, however, when the values entered are equal, the button remains disabled, and a warning that the passwords do not match still remains.

Below is the HTML code:

<div class="form-group mb-3">
                <label class="label" for="password">Password</label>
              <input id="password" type="password" class="form-control" placeholder="Password" name="passcode" required>
              <span toggle="#password" class="fa fa-fw fa-eye field-icon toggle-password"></span>
            </div>
            <div class="form-group mb-3">
                <label class="label" for="confirmPassword">Confirm Password</label>
              <input id="confirmPassword" type="password" class="form-control passcode" placeholder="Confirm Password" name="passCode" required onkeypress="checkConfirmation()">
              <span toggle="#confirmPassword" class="fa fa-fw fa-eye field-icon toggle-password"></span>
            </div>
            <span id="notEqualPassCode"></span>

Below is the javascript code for the checkConfirmation() function:

<script type="text/javascript">
function checkConfirmation(){
    var passcode = document.getElementById("password").value;
    var confirmPasscode = document.getElementById("confirmPassword").value;
    let btnSubmit = document.querySelector(".submit");
    btnSubmit.disabled = true;

    if (passcode != confirmPasscode){
        btnSubmit.disabled = true;
        document.getElementById("notEqualPassCode").innerHTML = '<i class="fa fa-fw fa-exclamation-triangle"></i>Passwords do not match!';
    } else {
        btnSubmit.disabled = false;
        document.getElementById("notEqualPasscode").innerHTML = '';
    }
}

Please someone tell me what could be wrong.

Svelte, updating class instance property inside the ‘use’ action function not updating on view

I’m trying to implement a form class that allows me to better implement working with forms in Svelte, but I’m running into the issue that when I update a instance property inside the ‘use’ action function… the new value is not getting updated in the view.

Here is the link to a REPL I’m working with:

https://svelte.dev/repl/13ac33881a184795947be6ae9f104834?version=3.44.3

Essentially what I’m trying to achieve in this piece of code is that when the user clicks into the input, the inputs bounded class instance ‘touched’ property gets updated in the ‘use’ action, which should in turn, re-render the ‘touched’ value in the UI.

I’m not sure why the value is not updating in the UI.

Any help to make understand what I’m doing wrong is greatly appreciated.

Script to fetch “range to sort” from google sheets not working (used to work)

I have data rows in multiple sections. I keep track of the start and end rows of each section in my google spreadsheet and they change dynamically as rows are inserted or deleted. I used App Script to fetch the current section X#:Y# from the spreadsheet and then run a script to sort it. This used to work perfectly, however, I recently did something that bricked it – and I cannot tell why…

Here’s an excerpt of the code:

function onEdit(){

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  var editedCell = sheet.getActiveCell();
  var columnToSortBy = 5;
  var tableRange = [];
  tableRange[0] = sheet.getRange(2,32).getValue(); //A6:K17
  tableRange[1] = sheet.getRange(3,32).getValue(); //A59:K62
  var range0 = sheet.getRange(tableRange[0]);
  var range1 = sheet.getRange(tableRange[1]);

if(editedCell.getColumn() == columnToSortBy){   


    range0.sort( { column : columnToSortBy } )
    range1.sort( { column : columnToSortBy } )

}
}

undefined variable?!
*Note: I copied the script from another StackOverflow post. It has served me well for nearly 2 months.

I tried looking at the debugger and my variables all appear as undefined. I tried manually replacing tableRange[0] with (for example) “A2:K10” and the script works fine. But as soon as I try the old way it stops working… I’m thinking this is something to do with JS as I’m totally ignorant of the language. Could you please help me?

.setValue going to specific cell rather than the next row

For some reason, whenever I run this function, it first takes a very long time to execute but secondly always replaces in cell E9, rather than going to the next available cell (in this case E10).

This is my code:

    
    var RecruitRosterRange = RecruitRoster.getRange(1,1,RecruitRosterLastRow,7);

    var RecruitRosterRangeValues = RecruitRosterRange.getValues();
  
    var RecruitRosterRow = 8;
    while (RecruitRosterRow <= RecruitRosterLastRow)

      {
      if (RecruitRosterRangeValues[RecruitRosterRow-1][1] == "")        // Is Website ID cell blank?
      {
        RecruitRoster.getRange(RecruitRosterRow, 5).setValue(AutomationSheet.getRange(asFTAddWebID).getValue()); // Add Website ID to website ID column on Recruit Roster
        RecruitRosterRow = RecruitRosterLastRow+1;
      }
      //Repeats if not
      else 
      {
        RecruitRosterRow++;
      }
    }```

And this is my sheet:
[sheet][1]


  [1]: https://i.stack.imgur.com/k6kXm.png

If you need any additional screenshots or explanation, please let me know. Thank you!