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!

error of Discord.js 13v “Syntax Error: agent ??= new https.Agent” on heroku

I recently tried to upload my new bot on 13v to heroku, but for my surprise it gives this error:

2021-12-24T19:32:08.411245+00:00 app[worker.1]: /app/node_modules/discord.js/src/rest/APIRequest.js:33
2021-12-24T19:32:08.411261+00:00 app[worker.1]: agent ??= new https.Agent({ ...this.client.options.http.agent, keepAlive: true });
2021-12-24T19:32:08.411262+00:00 app[worker.1]: ^^^
2021-12-24T19:32:08.411262+00:00 app[worker.1]:
2021-12-24T19:32:08.411262+00:00 app[worker.1]: SyntaxError: Unexpected token '??='
2021-12-24T19:32:08.411262+00:00 app[worker.1]: at wrapSafe (internal/modules/cjs/loader.js:1001:16)
2021-12-24T19:32:08.411263+00:00 app[worker.1]: at Module._compile (internal/modules/cjs/loader.js:1049:27)
2021-12-24T19:32:08.411263+00:00 app[worker.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-12-24T19:32:08.411263+00:00 app[worker.1]: at Module.load (internal/modules/cjs/loader.js:950:32)
2021-12-24T19:32:08.411263+00:00 app[worker.1]: at Function.Module._load (internal/modules/cjs/loader.js:790:12)
2021-12-24T19:32:08.411264+00:00 app[worker.1]: at Module.require (internal/modules/cjs/loader.js:974:19)
2021-12-24T19:32:08.411264+00:00 app[worker.1]: at require (internal/modules/cjs/helpers.js:93:18)
2021-12-24T19:32:08.411265+00:00 app[worker.1]: at Object.<anonymous> (/app/node_modules/discord.js/src/rest/RESTManager.js:4:20)
2021-12-24T19:32:08.411265+00:00 app[worker.1]: at Module._compile (internal/modules/cjs/loader.js:1085:14)
2021-12-24T19:32:08.411265+00:00 app[worker.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-12-24T19:32:08.533679+00:00 heroku[worker.1]: Process exited with status 1
2021-12-24T19:32:08.589332+00:00 heroku[worker.1]: State changed from up to crashed
2021-12-24T19:34:09.000000+00:00 app[api]: Build started by user [email protected]
2021-12-24T19:34:22.000000+00:00 app[api]: Build succeeded
2021-12-24T19:34:22.191934+00:00 app[api]: Deploy b3f02b01 by user [email protected]
2021-12-24T19:34:22.191934+00:00 app[api]: Release v6 created by user [email protected]
2021-12-24T19:34:24.110959+00:00 heroku[worker.1]: State changed from crashed to starting
2021-12-24T19:34:26.145669+00:00 heroku[worker.1]: Starting process with command `node index.js`
2021-12-24T19:34:26.812717+00:00 heroku[worker.1]: State changed from starting to up
2021-12-24T19:34:27.250285+00:00 app[worker.1]: /app/node_modules/discord.js/src/rest/APIRequest.js:33
2021-12-24T19:34:27.250299+00:00 app[worker.1]: agent ??= new https.Agent({ ...this.client.options.http.agent, keepAlive: true });
2021-12-24T19:34:27.250299+00:00 app[worker.1]: ^^^
2021-12-24T19:34:27.250300+00:00 app[worker.1]:
2021-12-24T19:34:27.250300+00:00 app[worker.1]: SyntaxError: Unexpected token '??='
2021-12-24T19:34:27.250300+00:00 app[worker.1]: at Module._compile (internal/modules/cjs/loader.js:1049:27)
2021-12-24T19:34:27.250301+00:00 app[worker.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-12-24T19:34:27.250301+00:00 app[worker.1]: at Module.load (internal/modules/cjs/loader.js:950:32)
2021-12-24T19:34:27.250301+00:00 app[worker.1]: at Function.Module._load (internal/modules/cjs/loader.js:790:12)
2021-12-24T19:34:27.250301+00:00 app[worker.1]: at Module.require (internal/modules/cjs/loader.js:974:19)
2021-12-24T19:34:27.250302+00:00 app[worker.1]: at require (internal/modules/cjs/helpers.js:93:18)
2021-12-24T19:34:27.250302+00:00 app[worker.1]: at Object.<anonymous> (/app/node_modules/discord.js/src/rest/RESTManager.js:4:20)
2021-12-24T19:34:27.250303+00:00 app[worker.1]: at Module._compile (internal/modules/cjs/loader.js:1085:14)
2021-12-24T19:34:27.250303+00:00 app[worker.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)

but it runs perfectly from my pc, I tried things like delete the whole index.js except the scensials things, nothing worked

React render HTML from Object [duplicate]

I am building a react website. As part of the site, I have a cards which are rendered using a JS map function. It looks like this:

return (
  <div className="cards">
     {HomeCard.map((item) => (
        <Card image={item.image} heading={item.heading} text={item.text} />
     ))}
  </div>
)

This gets data from another file which contains this object:

const homeCardsText = [
    {
        id: 1,
        image: web_design,
        heading: "Web Design",
        text: "<strong>Lorem ipsum</strong> dolor sit amet, consectetur adipiscing elit. Maecenas leo arcu, sagittis eget varius vel, fringilla nec metus. Nullam ultrices felis nec fermentum tincidunt. Maecenas tincidunt commodo ante a dapibus"
    },
    {
        id: 2,
        image: web_dev,
        heading: "Web Development",
        text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas leo arcu, sagittis eget varius vel, fringilla nec metus. Nullam ultrices felis nec fermentum tincidunt. Maecenas tincidunt commodo ante a dapibus."
    },
    {
        id: 3,
        image: web_accessibility,
        heading: "Web Accessibility",
        text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas leo arcu, sagittis eget varius vel, fringilla nec metus. Nullam ultrices felis nec fermentum tincidunt. Maecenas tincidunt commodo ante a dapibus."
    },
];

export default homeCardsText;

Note very specifically in id:1 there are HTML tags. When this is rendered to the front end, the HTML becomes sanitized and renders as plaintext. How do I get this to render as HTML?

TypeError: null is not an object (evaluating ‘daysData.map’) – Trying to map over array of objects

Hope you’re all doing good, I’ve tried looking around for a specific answer regarding this issue I’m having in ReactJS where I’m trying to map over an array I’m fetching via my local system and I keep getting this error in the console:

TypeError: null is not an object (evaluating 'daysData.map')

Here is a snapshot of my bit of code where I’m initializing the array from fetch:
Fetched data to Array

And here it is in text format:

// Here I initalize the array with useState
  const [daysData, setDaysData] = useState(null);

  // Here is the port I'm fetching my array from.
  useEffect(() => {
    fetch('http://localhost:5001/chocolates')
      .then((resp) => resp.json())
      .then((data) => setDaysData(data));
  }, []);

  // Console logging is sending back the array with no issues
  console.log(daysData);

And here is the map function where I’m trying to render a with the ‘id’ key from the array:

Array.map not working

Here is the bit of code in text format:

{/* Here I'm getting the error " TypeError: null is not an object (evaluating 'daysData.map') " */}
      {daysData.map((day) => (
        <div>{day.id}</div>
      ))}

And here is an example of the array where I’ve fetched data from in which I’m trying to map over:
Array and Objects Within

Thanks for any help in advance

Showing data on an ag-grid using Flask

I’m a newbie at this and would appreciate some guidance. I’m trying to show some data from Python in an ag-grid on HTML, using Flask and JS, but don’t seem to getting anywhere. Could someone please help me ?

This is the Python code with the rowData that I want to show in an ag-grid:

from flask import Flask, render_template, request
import pandas as pd

app = Flask(__name__)

@app.route('/')
def settings():
    rowData = [{ make: "Toyota", model: "Celica", price: 35000 },
    { make: "Ford", model: "Mondeo", price: 32000 },
    { make: "Porsche", model: "Boxter", price: 72000 }]

    return render_template('settings.html', rowData=rowData)

I’ve put the ag-grid into a JS function and wanted to call it from the HTML:

function myFunc(rowData) {
      
     const columnDefs = [
        { field: "make" },
        { field: "model" },
        { field: "price" }
       ];

      // let the grid know which columns and what data to use
      const gridOptions = {
        columnDefs: columnDefs,
        rowData: rowData
      };
      
      // setup the grid after the page has finished loading
      document.addEventListener('DOMContentLoaded', () => {
          const gridDiv = document.querySelector('#myGrid');
          new agGrid.Grid(gridDiv, gridOptions);
      });
}

The HTML code:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Ag-Grid Basic Example</title>
    <script src="https://unpkg.com/ag-grid-community/dist/ag-grid-community.min.js"></script>
    <script src="app.js" type="text/javascript">
        myVar = myFunc({{rowData|tojson}})
    </script>
</head>
<body>
    <div id="myGrid" style="height: 200px; width:500px;" class="ag-theme-alpine"></div>
</body>
</html>

Convert React native BLE response from device

I’m writing to you as I need help converting a reply from BLE device, and I want to convert it to comprehensible data, but I’m failing to. I’m using React native BLE manager library, and the documentation for the bluetooth device Is like this.

"peripheral": "D6:AD:15:67:4A:A5", "service": "XXXXX-XXXXX-XXXXXX", "value": [85, 0, 255, 0, 0, 13, 0, 96, 93, 0, 0, 0, 0, 0, 49, 0, 0, 0, 1, 0]

enter image description here

Error: transaction underpriced while deploying to rinkeby

The below code just stops working at the line “Attempting to deploy from account: ..” in console and after sometime it gives “Trnsaction was not mined within 750s, please make sure your transaction was sent properly”, Earlier it was giving the error “transaction underpriced”, I tried adding gasPrice and increasing the gas price but still got the same result. can anyone help me out ?

const hdWalletProvider = require('@truffle/hdwallet-provider')
const Web3 = require('web3')
const { interface, bytecode } = require('./compile')

const provider = new hdWalletProvider(
  'fee brass payment tiny edge spoon control trophy provide rather harbor course',
  'https://rinkeby.infura.io/v3/53ed6ca9c43446a98fb1f9f799d2ca8f'
)

const web3 = new Web3(provider)

const deploy = async () => {
  const accounts = await web3.eth.getAccounts()

  console.log('Attempting to deploy from account:' + accounts[0])

  const result = await new web3.eth.Contract(JSON.parse(interface))
    .deploy({
      data: bytecode,
      arguments: ['hello there!'],
    })
    .send({ gas: '1000000', from: accounts[0] })

  console.log('Contract deployed to:' + result.options.address)
  provider.engine.stop()
}
deploy()

Why it doesn’t change colours? It’s JavaScript

Why doesn’t it change colours? Why do I have error: ts(1003)?

<html>
   <head>
       <script>
           var peso = prompt("Dime tu peso en kg")
           var altura = prompt("Dime tu altura en metros")
           var IMC = parseFloat(peso) / parseFloat(altura)**2
           if (IMC < 19) {
               document.write("Estás por debajo de tu peso ideal")
           } else {
               document.write("Obesidad")
           }
       </script>
   </head>
</html>

how to log [ 1, 2 ,3] not [1.0,2.0,3.0] as my array? [closed]

I’m am very new to programming and trying to salve a programing puzzle/game.
It’s a Spiral Matrix and the result is correct but
my array is outputting .0 at the end of my arrays.

example

input is [ 1, 2, 3],
         [ 4, 5, 6],
         [ 7, 8, 9]

output is [1.0,2.0,3.0,6.0,9.0,8.0,7.0,4.0,5.0]

looking for [ 1, 2, 3, 6, 9, 8, 7, 4, 5]

the code I am using is from this youtube video.
LeetCode 54 Spiral Matrix in javascript

how do I Logger.log(result) without the .0?


    function myFunction() {
    matrix = [
    [ 1, 2, 3], 
    [ 4, 5, 6], 
    [ 7, 8, 9]
             ];
    // result array
    const result = [];
    // boundry varibals
    let left = 0;
    let top = 0;
    let right = matrix[0].length - 1;
    let bottom = matrix.length - 1;
    // starting direction clock wise
    let direction = 'right';
    // start loop
    while (left <= right && top <= bottom) {

    if (direction === 'right') {
      for (let i = left; i <= right; i += 1) {
        result.push(matrix[top][i]);
      }
      top += 1;
      direction = 'down';
    }

    else if (direction === 'down') {
      for (let i = top; i <= bottom; i += 1) {
        result.push(matrix[i][right]);
      }
      right -= 1;
      direction = 'left';
    }

    else if (direction === 'left') {
      for (let i = right; i >= left; i -= 1) {
        result.push(matrix[bottom][i]);
      }
      bottom -= 1;
      direction = 'up';
    }

    else if (direction === 'up') {
      for (let i = bottom; i >= top; i -= 1) {
        result.push(matrix[i][left]);

      }

      left += 1;
      direction = 'right';
    }
    }
    Logger.log(result);
    return result;
    }

I hope this question is simple I don’t know what else I should add the puzzle is from an indie game BitRunner it got me more into programming than I use to be in adding this info at the end because the post won’t submit if it has more code then words

Flutter web with wcf service

I’m trying to call wcf service from flutter
Using https

It’s working from android emulator
But when I’m trying to call it from flutter web I get XMLhttprequest error

Any solution?????