for loop to generate time list in javascript

I want to generate this data list (00:00 ~ 24:00, every 3 minutes)

[ "00:00", "00:03", "00:06", "00:09", "00:12", "00:15", "00:18", "00:21", "00:24", "00:27", "00:30", "00:33", "00:36", "00:39", "00:42", "00:45", "00:48", "00:51", "00:54", "00:57", "01:00", "01:03", "01:06", "01:09", "01:12", "01:15", "01:18", "01:21", "01:24", "01:27", "01:30", "01:33", "01:36", "01:39", "01:42", "01:45", "01:48", "01:51", "01:54", "01:57", "02:00", "02:03", "02:06", "02:09", "02:12", "02:15", "02:18", "02:21", "02:24", "02:27", "02:30", "02:33", "02:36", "02:39", "02:42", "02:45", "02:48", "02:51", "02:54", "02:57", "03:00", "03:03", "03:06", "03:09", "03:12", "03:15", "03:18", "03:21", "03:24", "03:27", "03:30", "03:33", "03:36", "03:39", "03:42", "03:45", "03:48", "03:51", "03:54", "03:57", "04:00", "04:03", "04:06", "04:09", "04:12", "04:15", "04:18", "04:21", "04:24", "04:27", "04:30", "04:33", "04:36", "04:39", "04:42", "04:45", "04:48", "04:51", "04:54", "04:57", "05:00", "05:03", "05:06", "05:09", "05:12", "05:15", "05:18", "05:21", "05:24", "05:27", "05:30", "05:33", "05:36", "05:39", "05:42", "05:45", "05:48", "05:51", "05:54", "05:57", "06:00", "06:03", "06:06", "06:09", "06:12", "06:15", "06:18", "06:21", "06:24", "06:27", "06:30", "06:33", "06:36", "06:39", "06:42", "06:45", "06:48", "06:51", "06:54", "06:57", "07:00", "07:03", "07:06", "07:09", "07:12", "07:15", "07:18", "07:21", "07:24", "07:27", "07:30", "07:33", "07:36", "07:39", "07:42", "07:45", "07:48", "07:51", "07:54", "07:57", "08:00", "08:03", "08:06", "08:09", "08:12", "08:15", "08:18", "08:21", "08:24", "08:27", "08:30", "08:33", "08:36", "08:39", "08:42", "08:45", "08:48", "08:51", "08:54", "08:57", "09:00", "09:03", "09:06", "09:09", "09:12", "09:15", "09:18", "09:21", "09:24", "09:27", "09:30", "09:33", "09:36", "09:39", "09:42", "09:45", "09:48", "09:51", "09:54", "09:57", "10:00", "10:03", "10:06", "10:09", "10:12", "10:15", "10:18", "10:21", "10:24", "10:27", "10:30", "10:33", "10:36", "10:39", "10:42", "10:45", "10:48", "10:51", "10:54", "10:57", "11:00", "11:03", "11:06", "11:09", "11:12", "11:15", "11:18", "11:21", "11:24", "11:27", "11:30", "11:33", "11:36", "11:39", "11:42", "11:45", "11:48", "11:51", "11:54", "11:57", "12:00", "12:03", "12:06", "12:09", "12:12", "12:15", "12:18", "12:21", "12:24", "12:27", "12:30", "12:33", "12:36", "12:39", "12:42", "12:45", "12:48", "12:51", "12:54", "12:57", "13:00", "13:03", "13:06", "13:09", "13:12", "13:15", "13:18", "13:21", "13:24", "13:27", "13:30", "13:33", "13:36", "13:39", "13:42", "13:45", "13:48", "13:51", "13:54", "13:57", "14:00", "14:03", "14:06", "14:09", "14:12", "14:15", "14:18", "14:21", "14:24", "14:27", "14:30", "14:33", "14:36", "14:39", "14:42", "14:45", "14:48", "14:51", "14:54", "14:57", "15:00", "15:03", "15:06", "15:09", "15:12", "15:15", "15:18", "15:21", "15:24", "15:27", "15:30", "15:33", "15:36", "15:39", "15:42", "15:45", "15:48", "15:51", "15:54", "15:57", "16:00", "16:03", "16:06", "16:09", "16:12", "16:15", "16:18", "16:21", "16:24", "16:27", "16:30", "16:33", "16:36", "16:39", "16:42", "16:45", "16:48", "16:51", "16:54", "16:57", "17:00", "17:03", "17:06", "17:09", "17:12", "17:15", "17:18", "17:21", "17:24", "17:27", "17:30", "17:33", "17:36", "17:39", "17:42", "17:45", "17:48", "17:51", "17:54", "17:57", "18:00", "18:03", "18:06", "18:09", "18:12", "18:15", "18:18", "18:21", "18:24", "18:27", "18:30", "18:33", "18:36", "18:39", "18:42", "18:45", "18:48", "18:51", "18:54", "18:57", "19:00", "19:03", "19:06", "19:09", "19:12", "19:15", "19:18", "19:21", "19:24", "19:27", "19:30", "19:33", "19:36", "19:39", "19:42", "19:45", "19:48", "19:51", "19:54", "19:57", "20:00", "20:03", "20:06", "20:09", "20:12", "20:15", "20:18", "20:21", "20:24", "20:27", "20:30", "20:33", "20:36", "20:39", "20:42", "20:45", "20:48", "20:51", "20:54", "20:57", "21:00", "21:03", "21:06", "21:09", "21:12", "21:15", "21:18", "21:21", "21:24", "21:27", "21:30", "21:33", "21:36", "21:39", "21:42", "21:45", "21:48", "21:51", "21:54", "21:57", "22:00", "22:03", "22:06", "22:09", "22:12", "22:15", "22:18", "22:21", "22:24", "22:27", "22:30", "22:33", "22:36", "22:39", "22:42", "22:45", "22:48", "22:51", "22:54", "22:57", "23:00", "23:03", "23:06", "23:09", "23:12", "23:15", "23:18", "23:21", "23:24", "23:27", "23:30", "23:33", "23:36", "23:39", "23:42", "23:45", "23:48", "23:51", "23:54", "23:57", "24:00" ],

I try to use for loop to generate “hour” first:

let arr = []
for (let i = 0; i < 25; i++) {
  let j = 19
  let str = i.toString()
  arr[j*i] = str.padStart(2, '0') + ':00'
}
console.log('arr', arr)

but I don’t know how to insert minutes like 00:03 ~ 00:57 in the array…

If statement based on Countdown Timer on ReactJS not working

I have a JS countdown timer that works great and displays great into my home page. Now, I’m trying to implement an IF statement in my rendered DIV to display a button for OPEN when Timer is at 0 or APP CLOSED if timer is still going. This is what I have on my React Home Page, and this is my Countdown.js Page:

This is the if statement: {distance < 0 ? OPEN : APP CLOSED}

Home Page

import React from 'react';
import '../../App.css';
import Countdown from '../Countdown';



const distance = Countdown ();


function Home() {






  return (
    <>
    <div className="App">
        <div>
          <div className='hero-container'>
          <div class="courses-container">
    <div class="course">
        <div class="course-preview">
            <h6>Welcome</h6>
            <h2>PROJECT NAME</h2>
      
        </div>
        <div class="course-info">
            <div class="progress-container">
                <span class="progress-text">
                    /1000
                </span>
            </div>
            <h2 id="demo"></h2>
      <div id='input-number' className='input-number-location'>
    <input className='input-number button' type="number" name="amount" defaultValue="1" min="1" max="20"/>
  </div>
            {distance < 0 ? <button class="btncard">OPEN</button> : <button class="btncard">APP CLOSED</button>}
        </div>
    {/*NEED TO FIX THIS IF STATEMENT / */}
    </div>
</div>
          </div>
        </div>
      </div>
    </>
  );
}

export default Home;

Countdown Timer

function Countdown () {

    
    // Set the date we're counting down to
var countDownDate = new Date("Jun 27, 2022 22:27:10").getTime();

// Update the count down every 1 second
var x = setInterval(function() {

  // Get today's date and time
  var now = new Date().getTime();
    
  // Find the distance between now and the count down date
  var distance = countDownDate - now;
    
  // Time calculations for days, hours, minutes and seconds
  var days = Math.floor(distance / (1000 * 60 * 60 * 24));
  var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  var seconds = Math.floor((distance % (1000 * 60)) / 1000);
    
  // Output the result in an element with id="demo"
  document.getElementById("demo").innerHTML = days + "d " + hours + "h "
  + minutes + "m " + seconds + "s ";
    
  // If the count down is over, write some text 
  if (distance < 0) {
    clearInterval(x);
    document.getElementById("demo").innerHTML = "Mint is Live!";
  
  }
}, 1000);

}

export default Countdown;

How can I ignore undefined values when updating Firestore data from a Google Cloud Function?

In my index.js file, I have:

const db = admin.firestore();
db.settings({ignoreUndefinedProperties:true});

In my other .js file with the actual function, I have:

const functions = require('firebase-functions');
const {Client, ReverseGeocodingLocationType, AddressType} = require("@googlemaps/google-maps-services-js");

async function addLocationData(addressComponents, reference){
    cityName = getLocationType(addressComponents, 'locality')
    stateName = getLocationType(addressComponents, 'administrative_area_level_1')
    countryName = getLocationType(addressComponents, 'country')
    await reference.set({
        'location.city': cityName,
        'location.state': stateName,
        'location.country': countryName
    },{ignoreUndefinedProperties:true})
    return true
}

However, I am still getting this error:

Value for argument "data" is not a valid Firestore document. 
Cannot use "undefined" as a Firestore value (found in field "`location.city`"). 
If you want to ignore undefined values, enable `ignoreUndefinedProperties`

The city data in this case is undefined, but I want to ignore undefined data.

Javascript: clone a function that is inside another function [duplicate]

I want to clone a function that is inside another function and pass new value. But in this case, is it possible?

function big({ message, info }) {
        function small() {
                console.log(message);
        }

        return { small }
}

const { small } = big({});
small() // this will print undefined

/* 
clone to a new function with different values
const small_clone = do something here with the small function, not touching the big one
small_clone({ message: 'hello' }) // this will print hello
*/

Filtering out multiple && duplicate values in an array

I’m struggling to find a clean way to reduce or filter an array to contain no duplicate set values, when 2 of the values match. Here is an example of the data I am using. I am trying to remove any duplicates where title && genre both match.

[
  {
    "title": "american-hustle",
    "genre": "arts",
    "user": "penny"
  },
  {
    "title": "american-hustle",
    "genre": "comedy",
    "user": "brian"
  },
  {
    "title": "platoon",
    "genre": "war",
    "user": "tom"
  },
  {
    "title": "american-hustle",
    "genre": "arts",
    "user": "sarah"
  },
  {
    "title": "american-hustle",
    "genre": "arts",
    "user": "john"
  }
]

So in this case, the final two items should be removed, as both title && genre match that of an existing entry. Note, the second item should remain as american-hustle with a genre comedy, is still unique.

I’ve tried to find a similar question but I’m struggling to find one. Any help would be greatly appreciated.

ElementClickInterceptedError: element click intercepted. Selenium Javascript Chromedriver

I am having problems with clicking an element in a dropdown. What i have to do is:

  1. Open https://pastebin.com
  2. paste “Hello from WebDriver”
  3. Set Paste Expiration to “10 Minutes”
  4. Set Paste Title to “helloweb”

However, after opening the dropdown some 3rd party ad content doesn’t let me click my button, which results in ElementClickInterceptedError

Here is my code

const {Browser} = require('selenium-webdriver');
const {Builder, By, Key, until} = require('selenium-webdriver');

(async function example() {
  let driver = await new Builder().forBrowser('chrome').build();
  driver.manage().window().maximize();

  try {
    await driver.get('https://pastebin.com');
    await driver.findElement(By.xpath('//*[@id="postform-text"]')).sendKeys('Hello from WebDriver');
    await driver.findElement(By.xpath('//*[@id="w0"]/div[5]/div[1]/div[2]/div/span/span[1]/span')).click()
    await driver.findElement(By.xpath("//*[@id="select2-postform-expiration-results"]/li[3]")).click();
    await driver.findElement(By.xpath('//*[@id="postform-name"]')).sendKeys('helloweb');

  finally {
    // await driver.quit();
  }
})();

How can I display a page only when all its components have been fully loaded? – Oracle Apex

I have a page that contains many components, for example one of them is region display selector and has the option: Include ‘Show All’ disabled, however when loading the page it is possible to display the items that should appear only in the second region of the region display selector and so on with the other regions that confirm the selector, I have also noticed that some fields that are hidden are displayed at the beginning while the page loads, how can I avoid this?
enter image description here

I have noticed that oracle apex page designer has it, how could I achieve something similar? I have searched the internet but I can’t find a solution, thanks.
enter image description here

I only have validations with javascript in page load DA
enter image description here

Is there another a better way to go about this Uncaught Type error? [duplicate]

I’m trying to create and append nested elements into and HTML but I keep getting the error down below.

const flasher = document.createElement('span');
const flasher_pikin = document.createTextNode("$500");

flasher.appendChild(flasher_pikin);

document.getElementsByClassName('inner_self').appendChild(flasher);

The Error

Uncaught TypeError: document.getElementsByClassName(...).appendChild is not a function

Can’t loop over Array created from Fetch() [duplicate]

I use Fetch() to retrieve data from an api end point. The data is fetched with no errors.
The data is a record from a database. I want to use this data to dynamically build a HTML table. However, when I create the array (tableArray in my code below) I cannot iterate over it. Now matter what I do it just gets ignored.

function getTableData() {
    let tableArray = [];
    fetch('/_my_worktable/').then(function(response){
        response.json().then(function(data){
            data.forEach((row) => {
                tableArray.push([row.ticket_number,
                row.type,
                row.short,
                row.priority.priority,
                row.requester.full_name,
                row.created,
                row.respond_by,
                row.resolve_by,
                row.respond_breach,
                row.resolve_breach]);
            });
        });
    });

    return tableArray;
};

The above is called when my page loads. I want to retrieve the data and send it to a function which should iterate through the Array. But the code gets to the loop and just ignores it. I tried to debug by putting a few different methods of loop iteration immediately after calling the fetch function as per the snippet below:

function initTable(){
    document.addEventListener('DOMContentLoaded', () => {
            let array = getTableData();
            console.log(array) 

             array.forEach(row => {
                console.log(row);
             })
             
            // loadTable(array)
    });
}

initTable();

When I run this the console.log(array) prints the expected array in the console but the array.forEach line just doesn’t seem to do anything (nothing shows in the console).

I have also tried

for(let row of array){
  console.log(row)
}

and

for(let row in array){
  console.log(array[row])
}

and even

for (let i = 0; i < array.length; i++) {
      console.log(array[i]);
};

But all of these are just ignored. It’s like they are not there at all, no error, nothing printed in the console. Yet the array definitely has data as just doing console.log(array) shows this:
enter image description here

What am I doing wrong?

Inline if-else runs twice in React

I have a problem when trying to go to different pages, the inline if-else runs twice 1 time for if and 1 time for else, for example: I added a log to the dashboard route and when “isAuthenticated” is true i get redirected to /dashboard but i also get the console log at the same time(if i have Navigate instead of log i get redirected twice that is the problem i am trying to fix) any idea why this is happening ?

import React, { Fragment, useState, useEffect } from "react";
import './App.css';
import "react-toastify/dist/ReactToastify.css";
import {BrowserRouter as Router, Routes, Route, Navigate} from "react-router-dom";
import { toast } from "react-toastify";

//components
import Login from "./components/Login";
import Register from "./components/Register";
import Dashboard from "./components/Dashboard";
import Home from "./components/Home";
import Auction from "./components/Auction";
//import Home from "./components/Home";


function App() {
  const checkAuthenticated = async () => {
    try {
      const res = await fetch("http://localhost:5000/auth/is-verify", {
        method: "GET",
        headers: { token: localStorage.token }
      
      });

      const parseRes = await res.json();

      parseRes === true ? setIsAuthenticated(true) : setIsAuthenticated(false);
    } catch (err) {
      console.error(err.message);
    }
  };

  useEffect(() => {
    checkAuthenticated();
  }, []);

  const [isAuthenticated, setIsAuthenticated] = useState(false);

  const setAuth = boolean => {
    setIsAuthenticated(boolean);
  };
  
//<Route path = '/auth' element = {<Auth/>} />
  return (
    <Fragment>
      <Router>
        <div className="container">
          <Routes>
          <Route path='/home' element = {
                isAuthenticated ? (
                  <Home setAuth={setAuth}  />
                ) : (
                  <Navigate to="/login" />
                )
              } />
            <Route path='/login' element = {
                !isAuthenticated ? (
                  <Login setAuth={setAuth}  />
                ) : (
                  <Navigate to="/home" />
                )
              } />
            <Route path='/register' element = {
                !isAuthenticated ? (
                  <Register setAuth={setAuth}  />
                ) : (
                  <Navigate to="/home" />
                )
              } />
           **<Route path='/dashboard' element = {
                isAuthenticated ? (
                  <Dashboard setAuth={setAuth}  />
                ) : (
                  console.log("dashboard")
                )
              } />**
              
              <Route path='/auction' element = {
               
                  <Auction setAuth={setAuth}  />
              
        
              } />
          </Routes>
        </div>
      </Router>
    </Fragment>
  );
};

export default App;

An easy way for escaping strings without causing REST syntax error?

Running this script:

  var query = 'SELECT 
    customer.id,
    customer.descriptive_name,
    group_placement_view.placement_type,
    group_placement_view.display_name,
    group_placement_view.placement,
    group_placement_view.target_url,
    metrics.impressions,
    metrics.cost_micros,
    metrics.conversions,
    metrics.video_views,
    metrics.video_view_rate,
    metrics.clicks,
    metrics.average_cpm,
    metrics.ctr
 FROM group_placement_view
 WHERE
    group_placement_view.placement_type IN ("YOUTUBE_CHANNEL")
    AND campaign.advertising_channel_type = "VIDEO"
    AND segments.date BETWEEN "'+ fromDate.query_date + '" AND "' + toDate.query_date + '"';

  var payload = {
    "pageSize": MAX_GADS_IDS,
    "query": query
  };

Shows in the logs an escaped string which leads to Google-Ads REST syntax error.
Is there a way make another form of escaping that won’t break the syntax?

enter image description here

enter image description here

How to make read more button [duplicate]

There is button for show more content and show less. But for some reason after click on button it show this error:

TypeError: Cannot read properties of null (reading ‘style’)
at myFunction ((index):343:12)

On line 343 is this: if (dots.style.display === “none”) {

HTML:

div class="container">
<div class="job-desc">content what show</div>
<span class="dots"></span>
<span class="more" style="display: none"> 
<div class="job-summary">content what show after click
</div>
</span>
<div class="job-more"><button onclick="myFunction(event)" class="myBtn" class="rm">READ MORE</button></div>
</div>

JS:

    <script>
function myFunction(event) {
  const parentSibling = event.target.parentElement.previousElementSibling;
  const dots = parentSibling.querySelector(".dots");
  const moreElement = parentSibling.querySelector(".more");
  const btnElement = event.target;

  if (dots.style.display === "none") {
    dots.style.display = "inline";
    btnElement.innerHTML = "READ MORE";
    moreElement.style.display = "none";
  } else {
    dots.style.display = "none";
    btnElement.innerHTML = "READ LESS";
    moreElement.style.display = "inline";
  }
}</script>

I cant find where is the error. Class dots is defined in HTML.

Javascript – comparing two dates ( minus X days) to see whether it’s true or false

I am trying to execute a code if a date (from a cookie) is older than about 2 days. More or less, it doesnt have to be precise.

The cookie value is : 2022-06-27T23:28:02.816Z

function getCookie(name) {
    var value = "; " + document.cookie;
    var parts = value.split("; " + name + "=");
    if (parts.length == 2) return parts.pop().split(";").shift();
}

Using :

getCookie(name) and : .slice(0, 10);

Returns : 2022-06-27
Therefore I now have a YYYY-MM-DD value

var stuff_cookiename = getCookie("cookiename").slice(0, 10);

Converting to a date format :

var t_date_refuscmp_todate = Date.parse(stuff_cookiename);

I now have something like this : 1656288000000

Now I want to compare it NOW’s date – 2 days
So I do :

var t_date_verif = new Date();
var t_date_verif_format = tc_date_verif.setDate(tc_date_verif.getDate() - 2);
                                            

Which brings me something like : 1656199936800

=====================

But if i compare my cookiedate vs todaysdate -2 days, it doesnt always seem to be working correctly.

t_date_refuscmp_todate < t_date_verif_format !!!

Any idea of what I am not doing right?
Maybe there is something a lot easier to do 🙂

Thanks !