Why value of c cos and javascript Math.cos is different?

I was just porting a c code to JavaScript and got stumbled on a weird issue, the value from c cos function is different from the value of Math.cos value which results in wrong output.

First
c cos:

cos(-1.570796) is 0.000000

while

First
JavaScript cos:

Math.cos(-1.570796) is 3.2679489653813835e-7

Second
c cos:

cos(-1.570796) is -1.000000

while

Second
JavaScript cos:

Math.cos(-1.570796) is -0.99999999999994

I can see that JavaScript Second one is close enough to -1.000000 but the first one is way off.

Can anyone please let me know how can i fix this?

How do I add CSS or JS to JSON that I’m retrieving from an API in Rails?

After several days of reading and learning, I’ve finally figured out how to call an API on a Rails app and display it on a page.

Obviously, the API is returning the request in a JSON format, which is what’s being displayed on the webpage. This is exactly what’s being displayed..

{"data"=>{"id"=>501, "active"=>true, "type"=>"domestic", "legacy_id"=>66, "country_id"=>1161, "logo_path"=>"https://cdn.sportmonks.com/images/soccer/leagues/501.png", "name"=>"Premiership", "is_cup"=>false, "is_friendly"=>false, "current_season_id"=>18369, "current_round_id"=>247456, "current_stage_id"=>77453684, "live_standings"=>true, "coverage"=>{"predictions"=>true, "topscorer_goals"=>true, "topscorer_assists"=>true, "topscorer_cards"=>true}, "season"=>{"data"=>{"id"=>18369, "name"=>"2021/2022", "league_id"=>501, "is_current_season"=>true, "current_round_id"=>247456, "current_stage_id"=>77453684}}}, "meta"=>{"plans"=>[{"name"=>"Football Free Plan", "features"=>"Standard", "request_limit"=>"180,60", "sport"=>"Soccer"}], "sports"=>[{"id"=>1, "name"=>"Soccer", "current"=>true}]}}

I’ve been working with Rails for 2 weeks, so just finally getting that up is a big win for me. Now, I need to find my next step.

My question is, where do I look now to customize that data that’s on the page? Even if all you provide is a link or maybe help me to make sure I’m asking the right questions, that’d be helpful.

Attach An Event Handler To Add To Cart Button on a Shopify page

Our Shopify store doesn’t have a way to restrict the text characters that are entered in the gift message field so customers do not include emojis. We checked with the Bold App support team and they don’t have a way to prohibit emojis in the message box. So we decided to develop a custom solution to do it. Here is the product page.

I am thinking of attaching an event handler that gets called when Add to Cart button is clicked that strips the emojis if any in the gift message before the form is submitted. I’ve not been able to find any post here in the community that already discussed something similar so I request someone to share some ideas for me to start with after having a look at the product page. I’m trying to implement the solution found on Stackoverflow in my product page.

How to detect emoji using javascript

axios token based authentication handle 401 – try get access token by using refresh token

How to handle by using axios with token based authentication 401 unauthenticated request? And here, I used axios interceptors request & response. But is the interceptors response I don’t know what can I do?

// import
import axios from "axios";

axios interceptors request

axios.interceptors.request.use(
  config => {
    const accessToken = localStorage.getItem("ACCESS-TOKEN");
    if (accessToken) {
      config.headers['Authorization'] = 'Bearer ' + accessToken;
    }
    config.headers['Content-Type'] = 'application/json';
    
    return config;
  },

  error => {
    return Promise.reject(error);
  }
);

axios interceptors response

axios.interceptors.response.use(
  response => {
    return response.data;
  },

  error => {
    const originalRequest = error.config;
    
    if (error.response.status === 401 && !originalRequest._retry) {
      originalRequest._retry = true;

      const refreshToken = localStorage.getItem("REFRESH-TOKEN");
      localStorage.removeItem("ACCESS-TOKEN");
      
      // ?????
      // how to handle
      // ?????
    }
    
    return Promise.reject(error);
  }
);

How do I display a modal only once per hour for each user?

I have a website that displays a model on index load. Currently it loads every single time you go to the index page. It gets very annoying to the users of the website. I was wondering if I can only display it once per hour per user? The website is located at wikiraces.com

<!-- MODAL FOR NEWS-->
<div id="div1" class="modal">

  <!-- Modal content -->
  <div class="modal-content">
    <span class="close">&times;</span>
    </div>
    <!-- Modal content -->
<div class="modal-content">
  <div class="modal-header">
    <span class="close">&times;</span>
    <h2>New Features/Updates</h2>
  </div>
  <div class="modal-body">
   <h4> <p>The Fewest Clicks Game is Back!</p> </h4> 
    <p>
    It was down for maintanece for 14 hours but finally it is back
    </p> 
  
    <h4> The Multiplayer host random page is here! </h4> 
    <p>
     You can now play multiplayer without the hassle of chosing your own start!
      <br> 
      <br>
      <a href="/html/about.html"> <b> Report bugs </b></a>

    </p>
  </div>
  <div class="modal-footer">
   <h5> Enjoy, and remember to share this website with your friends! </h5>
  </div>
</div>
  </div>

</div> 

<script>
  // Get the modal
var modal = document.getElementById("div1");

// Get the <span> element that closes the modal
var spanTimed = document.getElementsByClassName("close")[0];

// When the user clicks on the button, open the modal
window.onload = function() {
  modal.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
spanTimed.onclick = function() {
  modal.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
  if (event.target == modal) {
    modal.style.display = "none"; 
  }
}

</script>

Null check operator used on a null value in WebView flutter

please a error when I try to reload my webview from a button : E/flutter (18150): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: Null check operator used on a null value

RaisedButton(
                        padding: const EdgeInsets.symmetric(vertical: 10,horizontal: 30),
                        onPressed: () async {
                          controller.reload();
                        },

this is my WebView

 WebView(
                  initialUrl: "https://wikoget.com",
                  javascriptMode: JavascriptMode.unrestricted,
                  onWebViewCreated: (controller){
                   this.controller=controller;
                  },
                  onPageFinished: (String url) {
                    controller
                        .evaluateJavascript("javascript:(function() { " +
                        "var head = document.getElementsByClassName('main-header-bar-wrap')[0];" +
                        "head.parentNode.style.cssText = ' position: sticky;position: -webkit-sticky; top : 0 ';" +
                        "var footer = document.getElementsByTagName('footer')[0];" +
                        "footer.parentNode.removeChild(footer);" +
                        "})()")
                        .then((value) => debugPrint('Page finished loading Javascript'));
                    },
                  onWebResourceError: (error) => setState(() {
                    controller.loadUrl("about:blank");
                    isError = true;
                  }),
                  gestureNavigationEnabled: true,
                ),

Get javascript object types as console.log outputs in node.js

I need to introspect some objects to know their type. In particular, I need to identify functions and async functions. For example consider the following object:

f = function(){}
af = async function(){}
class c {}

Using typeof won’t work because for any of these objects, the type is function


> typeof f
'function'
> typeof af
'function'
> typeof c
'function'

This improves a little if I use Object.prototype.toString.call() on each object:

> Object.prototype.toString.call(f)
'[object Function]'
>Object.prototype.toString.call(af)
'[object AsyncFunction]'
>Object.prototype.toString.call(c)
'[object Function]'

I still, cannot differentiate a function from a class. However, console.log is able to do it:

> console.log(f)
[Function: f]
> console.log(af)
[AsyncFunction: af]
> console.log(c)
[class c]

So my question is, how can I mimic what console.log is doing to identify the correct type of a class?

Mainslider sets a pool of points – Subsliders take points + set max depending on points left

Have a mainslider – this fills up total points field.
subsliders take points from the total points until it reaches 0. can’t go below zero.

added some code, show what i have. subsliders nicely take over maximum from the mainslider.
when i reduce mainsliders, so do subsliders.

right now subsliders only look at max from mainslider as their max. but what should happen, if there isn’t enough points left, it should take another Max.

Example:
You’ll see if you max out main bar, you can max out sub slider 1 and 2, but the 3th slider should be blocked after a few points, because it takes spent points below zero
Anyone able to alter the code this way?

let slider = document.getElementById("sliderMain");
let output = document.getElementById("outMain");
let slider1 = document.getElementById("sub1");
let output1 = document.getElementById("out1");
let slider2 = document.getElementById("sub2");
let output2 = document.getElementById("out2");
let slider3 = document.getElementById("sub3");
let output3 = document.getElementById("out3");
let cumul1Line = [0,0,2,5,9,14,20,27,35,44,54,65,77,90,104,119,135,152,170,189,209,230,252,275,299,324,350,377,405,434,464,495,527,560,594,629,665,702,740,779,819,860,902,945,989,1034,1080,1127,1175,1224,1274];
let mainTotal = [0,2,5,9,14,27,42,59,78,100,124,150,178,208,241,276,313,352,393,437,483,531,851,633,688,754,804,865,928,994,1062,1132,1204,1278,1355,1434,1515,1598,1683,1771,1815,1905,1950,2042,2088,2182,2229,2325,2373,2472,2521,2622,2672,2775,2826,2931,2983,3090,3143,3253];


function outMain(e){
  output.innerHTML = slider.value;
  const io = e.currentTarget.elements;
  let max = io.outMain.value;
    io.total.value = mainTotal[io.outMain.value];
    io.spent.value = +io.points1.value + +io.points2.value + +io.points3.value;
    io.left.value = io.total.value - io.spent.value;
    

  io.sub1.max = max;
  io.out1.value = io.sub1.value;
  io.points1.value = cumul1Line[io.out1.value]
  io.sub2.max = max;
  io.out2.value = io.sub2.value;
  io.points2.value = cumul1Line[io.out2.value]
  io.sub3.max = max;
  io.out3.value = io.sub3.value;
  io.points3.value = cumul1Line[io.out3.value]

};
document.forms.ui.oninput = outMain;
#total,#spent,#left{width:50px;}
<form id="ui">
  <div id="mainslider">
    <label for="main" class="labels2">Level</label><output form="ui" id="outMain"></output>
    <input type="range" min="1" max="50" value="1" step="1" class="slider" id="sliderMain">
    <input type="number" min="0" value="0" id="total">
    <input type="number" min="0" value="0" id="spent">
    <input type="number" min="0" value="0" id="left">
  </div>


  <div id="subslider1">
    <output form="ui" id="out1">1</output>
    <input type="range" min="1" max="50" value="1" step="1" class="slider" id="sub1">
    <input type="number" min="0" value="0" id="points1">
  </div>
  <div id="subslider1">
    <output form="ui" id="out2">1</output>
    <input type="range" min="1" max="50" value="1" step="1" class="slider" id="sub2">
    <input type="number" min="0" value="0" id="points2">
  </div>
  <div id="subslider1">
    <output form="ui" id="out3">1</output>
    <input type="range" min="1" max="50" value="1" step="1" class="slider" id="sub3">
    <input type="number" min="0" value="0" id="points3">
  </div>
  
</form>

How to implement Microsoft Azure Blob storage for browser with environment variables?

I am trying to implement a web application that connects to Microsoft Azure in order to upload files to their cloud storage. The documentation I have been following is Manage blobs with JavaScript v12 SDK in a browser. The tutorial for which is below:

https://docs.microsoft.com/en-us/azure/storage/blobs/quickstart-blobs-javascript-browser

The documentation explicitly states that to use Azure SDK libraries on a website, you must convert your code to work inside the browser using a bundler. The bundler suggested is parcel-bundler

I have built the project fine, and everything is working in the browser as per the tutorial outlines however I am running into an issue when it comes to obscuring the API Keys.

The alternative tutorial, which explains uploading Azure blobs using Node.js suggests the use of environment variables:

https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-nodejs

I have done this in my browser tutorial, however, when parcel bundles the project together the full API Keys can be accessed by looking in the source files suggesting they are revealed during the build process of the bundle.

It appears that I need to use a bundler as the functions used for browser use do not exist in the client-side JavaScript.

How do I get around this problem?

How to echo the selected value from a dropdown list?

I have the list of cities and provinces in my country and I added it on the dropdown list.
This is where I am getting the list

var cities={'Abra':['Bangued','Boliney','Bucay','Bucloc','Daguioman','Danglas','Dolores','La Paz','Lacub','Lagangilang','Lagayan','Langiden','Licuan-Baay','Luba','Malibcong','Manabo','Peñarrubia','Pidigan','Pilar','Sallapadan','San Isidro','San Juan','San Quintin','Tayum','Tineg','Tubo','Villaviciosa'],'Agusan del Norte':['Buenavista','Butuan','Cabadbaran','Carmen','Jabonga','Kitcharao','Las Nieves','Magallanes','Nasipit','Remedios T. Romualdez','Santiago','Tubay'],'Agusan del Sur':['Bayugan','Bunawan','Esperanza','La Paz','Loreto','Prosperidad','Rosario','San Francisco','San Luis','Santa Josefa','Sibagat','Talacogon','Trento','Veruela'],'Aklan':['Altavas','Balete','Banga','Batan','Buruanga','Ibajay','Kalibo','Lezo','Libacao','Madalag','Makato','Malay','Malinao','Nabas','New Washington','Numancia','Tangalan'],'Albay':['Bacacay','Camalig','Daraga','Guinobatan','Jovellar','Legazpi','Libon','Ligao','Malilipot','Malinao','Manito','Oas','Pio Duran','Polangui','Rapu-Rapu','Santo Domingo','Tabaco','Tiwi'],'Antique':['Anini-y','Barbaza','Belison','Bugasong','Caluya','Culasi','Hamtic','Laua-an','Libertad','Pandan','Patnongon','San Jose de Buenavista','San Remigio','Sebaste','Sibalom','Tibiao','Tobias Fornier','Valderrama'],'Apayao':['Calanasan','Conner','Flora','Kabugao','Luna','Pudtol','Santa Marcela'],'Aurora':['Baler','Casiguran','Dilasag','Dinalungan','Dingalan','Dipaculao','Maria Aurora','San Luis'],'Basilan':['Akbar','Al-Barka','Hadji Mohammad Ajul','Hadji Muhtamad','Isabela City','Lamitan','Lantawan','Maluso','Sumisip','Tabuan-Lasa','Tipo-Tipo','Tuburan','Ungkaya Pukan'],'Bataan':['Abucay','Bagac','Balanga','Dinalupihan','Hermosa','Limay','Mariveles','Morong','Orani','Orion','Pilar','Samal',],'Batanes':['Basco','Itbayat','Ivana','Mahatao','Sabtang','Uyugan'],'Batangas':['Agoncillo','Alitagtag','Balayan','Balete','Batangas City','Bauan','Calaca','Calatagan','Cuenca','Ibaan','Laurel','Lemery','Lian','Lipa','Lobo','Mabini','Malvar','Mataas na kahoy','Nasugbu','Padre Garcia','Rosario','San Jose','San Juan','San Luis','San Nicolas','San Pascual','Santa Teresita','Santo Tomas','Taal','Talisay','Tanauan','Taysan','Tingloy','Tuy'],'Benguet':['Atok','Baguio','Bakun','Bokod','Buguias','Itogon','Kabayan','Kapangan','Kibungan','La Trinidad','Mankayan','Sablan','Tuba','Tublay'],'Biliran':['Almeria','Biliran','Cabucgayan','Caibiran','Culaba','Kawayan','Maripipi','Naval'],'Bohol':['Alicia','Anda','Batuan','Bilar','Candijay','Carmen','Dimiao','Duero','Garcia Hernandez','Guindulman','Jagna','Sevilla','Lila','Loay','Loboc','Mabini','Pilar','Sierra Bullones','Valencia'],'Bukidnon':['Baungon','Cabanglasan','Damulog','Dangcagan','Don Carlos','Impasugong','Kadingilan','Kalilangan','Kibawe','Kitaotao','Lantapan','Libona','Malaybalay','Malitbog','Manolo Fortich','Maramag','Pangantucan','Quezon','San Fernando','Sumilao','Talakag','Valencia'],'Bulacan':['Angat','Balagtas','Baliuag','Bocaue','Bulakan','Bustos','Calumpit','Doña Remedios Trinidad','Guiguinto','Hagonoy','Malolos','Marilao','Meycauayan','Norzagaray','Obando','Pandi','Paombong','Plaridel','Pulilan','San Ildefonso','San Jose del Monte','San Miguel','San Rafael','Santa Maria'],'Cagayan':['Abulug','Alcala','Allacapan','Amulung','Aparri','Baggao','Ballesteros','Buguey','Calayan','Camalaniugan','Claveria','Enrile','Gattaran','Gonzaga','Iguig','Lal-lo','Lasam','Pamplona','Peñablanca','Piat','Rizal','Sanchez-Mira','Santa Ana','Santa Praxedes','Santa Teresita','Santo Niño','Solana','Tuao','Tuguegarao City'],'Camarines Norte':['Basud','Capalonga','Daet','Jose Panganiban','Labo','Mercedes','Paracale','San Lorenzo Ruiz','San Vicente','Santa Elena','Talisay','Vinzons',],'Camarines Sur':['Baao','Balatan','Bato','Bombon','Buhi','Bula','Cabusao','Calabanga','Camaligan','Canaman','Caramoan','Del Gallego','Gainza','Garchitorena','Goa','Iriga','Lagonoy','Libmanan','Lupi','Magarao','Milaor','Minalabac','Nabua','Naga','Ocampo','Pamplona','Pasacao','Pili','Presentacion','Ragay','Sagñay','San Fernando','San Jose','Sipocot','Siruma','Tigaon','Tinambac'],'Camiguin':['Catarman','Guinsiliban','Mahinog','Mambajao','Sagay'],'Capiz':['Cuartero','Dao','Dumalag','Dumarao','Ivisan','Jamindan','Maayon','Mambusao','Panay','Panitan','Pilar','Pontevedra','President Roxas','Roxas City','Sapian','Sigma','Tapaz'],'Catanduanes':['Bagamanoc','Baras','Bato','Caramoran','Gigmoto','Pandan','Panganiban','San Andres','San Miguel','Viga','Virac'],'Cavite':['Alfonso','Amadeo','Bacoor','Carmona','Cavite City','Dasmariñas','General Emilio Aguinaldo','General Mariano Alvarez','General Trias','Imus','Indang','Kawit','Magallanes','Maragondon','Mendez','Naic','Noveleta','Rosario','Silang','Tagaytay','Tanza','Ternate','Trece Martires'],'Cebu':['Alcantara','Alcoy','Alegria','Aloguinsan','Argao','Asturias','Badian','Balamban','Bantayan','Barili','Bogo','Boljoon','Borbon','Carcar','Carmen','Catmon','Cebu City','Compostela','Consolacion','Cordova','Daanbantayan','Dalaguete','Danao','Dumanjug','Ginatilan','Lapu-Lapu','Liloan','Madridejos','Malabuyoc','Mandaue','Medellin','Minglanilla','Moalboal','Naga','Oslob','Pilar','Pinamungajan','Poro','Ronda','Samboan','San Fernando','San Francisco','San Remigio','Santa Fe','Santander','Sibonga','Sogod','Tabogon','Tabuelan','Talisay','Toledo','Tuburan','Tudela'],'Compostela Valley':['Compostela','Laak','Mabini','Maco','Maragusan','Mawab','Monkayo','Montevista','Nabunturan','New Bataan','Pantukan'],'Cotabato':['Alamada','Aleosan','Antipas','Arakan','Banisilan','Carmen','Kabacan','Kidapawan','Libungan','M'lang','Magpet','Makilala','Matalam','Midsayap','Pigcawayan','Pikit','President Roxas','Tulunan'],'Davao del Norte':['Asuncion','Braulio E. Dujali','Carmen','Kapalong','New Corella','Panabo','Samal','San Isidro','Santo Tomas','Tagum','Talaingod'],'Davao del Sur':['Bansalan','Davao City','Digos','Hagonoy','Kiblawan','Magsaysay','Malalag','Matanao','Padada','Santa Cruz','Sulop'],'Davao Oriental':['Baganga','Banaybanay','Boston','Caraga','Cateel','Governor Generoso','Lupon','Manay','Mati','San Isidro','Tarragona'],'Dinagat Islands':['Basilisa','Cagdianao','Dinagat','Libjo','Loreto','San Jose','Tubajon'],'Eastern Samar':['Arteche','Balangiga','Balangkayan','Borongan','Can-avid','Dolores','General MacArthur','Giporlos','Guiuan','Hernani','Jipapad','Lawaan','Llorente','Maslog','Maydolong','Mercedes','Oras','Quinapondan','Salcedo','San Julian','San Policarpo','Sulat','Taft'],'Guimaras':['Buenavista','Jordan','Nueva Valencia','San Lorenzo','Sibunag'],'Ifugao':['Aguinaldo','Alfonso Lista','Asipulo','Banaue','Hingyon','Hungduan','Kiangan','Lagawe','Lamut','Mayoyao','Tinoc'],'Ilocos Norte':['Adams','Bacarra','Badoc','Bangui','Banna','Batac','Burgos','Carasi','Currimao','Dingras','Dumalneg','Laoag','Marcos','Nueva Era','Pagudpud','Paoay','Pasuquin','Piddig','Pinili','San Nicolas','Sarrat','Solsona','Vintar'],'Ilocos Sur':['Alilem','Banayoyo','Bantay','Burgos','Cabugao','Candon','Caoayan','Cervantes','Galimuyod','Gregorio del Pilar','Lidlidda','Magsingal','Nagbukel','Narvacan','Quirino','Salcedo','San Emilio','San Esteban','San Ildefonso','San Juan','San Vicente','Santa','Santa Catalina','Santa Cruz','Santa Lucia','Santa Maria','Santiago','Santo Domingo','Sigay','Sinait','Sugpon','Suyo','Tagudin','Vigan'],'Iloilo':['Ajuy','Alimodian','Anilao','Badiangan','Balasan','Banate','Barotac Nuevo','Barotac Viejo','Batad','Bingawan','Cabatuan','Calinog','Carles','Concepcion','Dingle','Dueñas','Dumangas','Estancia','Guimbal','Igbaras','Iloilo City','Janiuay','Lambunao','Leganes','Lemery','Leon','Maasin','Miagao','Mina','New Lucena','Oton','Passi','Pavia','Pototan','San Dionisio','San Enrique','San Joaquin','San Miguel','San Rafael','Santa Barbara','Sara','Tigbauan','Tubungan','Zarraga'],'Isabela':['Alicia','Angadanan','Aurora','Benito Soliven','Burgos','Cabagan','Cabatuan','Cauayan','Cordon','Delfin Albano','Dinapigue','Divilacan','Echague','Gamu','Ilagan','Jones','Luna','Maconacon','Mallig','Naguilian','Palanan','Quezon','Quirino','Ramon','Reina Mercedes','Roxas','San Agustin','San Guillermo','San Isidro','San Manuel','San Mariano','San Mateo','San Pablo','Santa Maria','Santiago','Santo Tomas','Tumauini'],'Kalinga':['Balbalan','Lubuagan','Pasil','Pinukpuk','Rizal','Tabuk','Tanudan','Tinglayan'],'La Union':['Agoo','Aringay','Bacnotan','Bagulin','Balaoan','Bangar','Bauang','Burgos','Caba','Luna','Naguilian','Pugo','Rosario','San Fernando','San Gabriel','San Juan','Santo Tomas','Santol','Sudipen','Tubao'],'Laguna':['Alaminos','Bay','Biñan','Cabuyao','Calamba','Calauan','Cavinti','Famy','Kalayaan','Liliw','Los Baños','Luisiana','Lumban','Mabitac','Magdalena','Majayjay','Nagcarlan','Paete','Pagsanjan','Pakil','Pangil','Pila','Rizal','San Pablo','San Pedro','Santa Cruz','Santa Maria','Santa Rosa','Siniloan','Victoria'],'Lanao del Norte':['Bacolod','Baloi','Baroy','Iligan','Kapatagan','Kauswagan','Kolambugan','Lala','Linamon','Magsaysay','Maigo','Matungao','Munai','Nunungan','Pantao Ragat','Pantar','Poona Piagapo','Salvador','Sapad','Sultan Naga Dimaporo','Tagoloan','Tangcal','Tubod'],'Lanao del Sur':['Amai Manabilang','Bacolod-Kalawi','Balabagan','Balindong','Bayang','Binidayan','Buadiposo-Buntong','Bubong','Butig','Calanogas','Ditsaan-Ramain','Ganassi','Kapai','Kapatagan','Lumba-Bayabao','Lumbaca-Unayan','Lumbatan','Lumbayanague','Madalum','Madamba','Maguing','Malabang','Marantao','Marawi','Marogong','Masiu','Mulondo','Pagayawan','Piagapo','Picong','Poona Bayabao','Pualas','Saguiaran','Sultan Dumalondong','Tagoloan II','Tamparan','Taraka','Tubaran','Tugaya','Wao'],'Leyte':['Abuyog','Alangalang','Albuera','Babatngon','Barugo','Bato','Baybay','Burauen','Calubian','Capoocan','Carigara','Dagami','Dulag','Hilongos','Hindang','Inopacan','Isabel','Jaro','Javier','Julita','Kananga','La Paz','Leyte','MacArthur','Mahaplag','Matag-ob','Matalom','Mayorga','Merida','Ormoc','Palo','Palompon','Pastrana','San Isidro','San Miguel','Santa Fe','Tabango','Tabontabon','Tacloban','Tanauan','Tolosa','Tunga','Villaba'],'Maguindanao':['Barira','Buldon','Datu Anggal Midtimbang','Datu Blah T. Sinsuat','Datu Odin Sinsuat','Kabuntalan','Matanog','Northern Kabuntalan','Parang','Sultan Kudarat','Sultan Mastura','Sultan Sumagka','Upi'],'Marinduque':['Boac','Buenavista','Gasan','Mogpog','Santa Cruz','Torrijos'],'Masbate':['Aroroy','Baleno','Balud','Batuan','Cataingan','Cawayan','Claveria','Dimasalang','Esperanza','Mandaon','Masbate City','Milagros','Mobo','Monreal','Palanas','Pio V. Corpuz','Placer','San Fernando','San Jacinto','San Pascual','Uson'],'Metro Manila':['Caloocan','Las Piñas','Makati','Malabon','Mandaluyong','Manila','Marikina','Muntinlupa','Navotas','Parañaque','Pasay','Pasig','Pateros','Quezon City','San Juan','Taguig','Valenzuela'],'Misamis Occidental':['Aloran','Baliangao','Bonifacio','Calamba','Clarin','Concepcion','Don Victoriano Chiongbian','Jimenez','Lopez Jaena','Oroquieta','Ozamiz','Panaon','Plaridel','Sapang Dalaga','Sinacaban','Tangub','Tudela'],'Misamis Oriental':['Alubijid','Balingasag','Balingoan','Binuangan','Cagayan de Oro','Claveria','El Salvador','Gingoog','Gitagum','Initao','Jasaan','Kinoguitan','Lagonglong','Laguindingan','Libertad','Lugait','Magsaysay','Manticao','Medina','Naawan','Opol','Salay','Sugbongcogon','Tagoloan','Talisayan','Villanueva'],'Mountain Province':['Barlig','Bauko','Besao','Bontoc','Natonin','Paracelis','Sabangan','Sadanga','Sagada','Tadian'],'Negros Occidental':['Bacolod','Bago','Binalbagan','Cadiz','Calatrava','Candoni','Cauayan','Enrique B. Magalona','Escalante','Himamaylan','Hinigaran','Hinoba-an','Ilog','Isabela','Kabankalan','La Carlota','La Castellana','Manapla','Moises Padilla','Murcia','Pontevedra','Pulupandan','Sagay','Salvador Benedicto','San Carlos','San Enrique','Silay','Sipalay','Talisay','Toboso','Valladolid','Victorias'],'Negros Oriental':['Amlan','Ayungon','Bacong','Bais','Basay','Bayawan','Bindoy','Canlaon','Dauin','Dumaguete','Guihulngan','Jimalalud','La Libertad','Mabinay','Manjuyod','Pamplona','San Jose','Santa Catalina','Siaton','Sibulan','Tanjay','Tayasan','Valencia','Vallehermoso','Zamboanguita'],'Northern Samar':['Allen','Biri','Bobon','Capul','Catarman','Catubig','Gamay','Laoang','Lapinig','Las Navas','Lavezares','Lope de Vega','Mapanas','Mondragon','Palapag','Pambujan','Rosario','San Antonio','San Isidro','San Jose','San Roque','San Vicente','Silvino Lobos','Victoria'],'Nueva Ecija':['Aliaga','Bongabon','Cabanatuan','Cabiao','Carranglan','Cuyapo','Gabaldon','Gapan','General Mamerto Natividad','General Tinio','Guimba','Jaen','Laur','Licab','Llanera','Lupao','Muñoz','Nampicuan','Palayan','Pantabangan','Peñaranda','Quezon','Rizal','San Antonio','San Isidro','Cabaritan','San Leonardo','Santa Rosa','Santo Domingo','Talavera','Talugtug','Zaragoza'],'Nueva Vizcaya':['Alfonso Castañeda','Ambaguio','Aritao','Bagabag','Bambang','Bayombong','Diadi','Dupax del Norte','Dupax del Sur','Kasibu','Kayapa','Quezon','Santa Fe','Solano','Villaverde'],'Occidental Mindoro':['Abra de Ilog','Calintaan','Looc','Lubang','Magsaysay','Mamburao','Paluan','Rizal','Sablayan','San Jose','Santa Cruz'],'Oriental Mindoro':['Baco','Bansud','Bongabong','Bulalacao','Calapan','Gloria','Mansalay','Naujan','Pinamalayan','Pola','Puerto Galera','Roxas','San Teodoro','Socorro','Victoria'],'Palawan':['Aborlan','Agutaya','Araceli','Balabac','Bataraza','Brooke's Point','Busuanga','Cagayancillo','Coron','Culion','Cuyo','Dumaran','El Nido','Kalayaan','Linapacan','Magsaysay','Narra','Puerto Princesa','Quezon','Rizal','Roxas','San Vicente','Sofronio Española','Taytay'],'Pampanga':['Angeles','Apalit','Arayat','Bacolor','Candaba','Floridablanca','Guagua','Lubao','Mabalacat','Macabebe','Magalang','Masantol','Mexico','Minalin','Porac','San Fernando','San Luis','San Simon','Santa Ana','Santa Rita','Santo Tomas','Sasmuan'],'Pangasinan':['Agno','Aguilar','Alaminos','Alcala','Anda','Asingan','Balungao','Bani','Basista','Bautista','Bayambang','Binalonan','Binmaley','Bolinao','Bugallon','Burgos','Calasiao','Dasol','Dagupan','Dasol','Infanta','Labrador','Laoac','Lingayen','Mabini','Malasiqui','Manaoag','Mangaldan','Mangatarem','Mapandan','Natividad','Pozorrubio','Rosales','San Carlos','San Fabian','San Jacinto','San Manuel','San Nicolas','San Quintin','Santa Barbara','Santa Maria','Santo Tomas','Sison','Sual','Tayug','Umingan','Urbiztondo','Urdaneta','Villasis'],'Quezon':['Agdangan','Alabat','Atimonan','Buenavista','Burdeos','Calauag','Candelaria','Catanauan','Dolores','General Luna','General Nakar','Guinayangan','Gumaca','Infanta','Jomalig','Lopez','Lucban','Lucena','Macalelon','Mauban','Mulanay','Padre Burgos','Pagbilao','Panukulan','Patnanungan','Perez','Pitogo','Plaridel','Polillo','Quezon','Real','Sampaloc','San Andres','San Antonio','San Francisco','San Narciso','Sariaya','Tagkawayan','Tayabas','Tiaong','Unisan'],'Quirino':['Aglipay','Cabarroguis','Diffun','Maddela','Nagtipunan','Saguday'],'Rizal':['Angono','Antipolo','Baras','Binangonan','Cainta','Cardona','Jalajala','Morong','Pililla','Rodriguez','San Mateo','Tanay','Taytay','Teresa'],'Romblon':['Alcantara','Banton','Cajidiocan','Calatrava','Concepcion','Corcuera','Ferrol','Looc','Magdiwang','Odiongan','Romblon','San Agustin','San Andres','San Fernando','San Jose','Santa Fe','Santa Maria'],'Samar':['Almagro','Basey','Calbayog','Calbiga','Catbalogan','Daram','Gandara','Hinabangan','Jiabong','Marabut','Matuguinao','Motiong','Pagsanghan','Paranas','Pinabacdao','San Jorge','San Jose de Buan','San Sebastian','Santa Margarita','Santa Rita','Santo Niño','Tagapul-an','Talalora','Tarangnan','Villareal','Zumarraga'],'Sarangani':['Alabel','Glan','Kiamba','Maasim','Maitum','Malapatan','Malungon'],'Shariff Kabunsuan':['Barira','Buldon','Datu Blah T. Sinsuat','Datu Odin Sinsuat','Kabuntalan','Matanog','Northern Kabuntalan','Parang','Sultan Kudarat','Sultan Mastura','Upi'],'Siquijor':['Enrique Villanueva','Larena','Lazi','Maria','San Juan','Siquijor'],'Sorsogon':['Barcelona','Bulan','Bulusan','Casiguran','Castilla','Donsol','Gubat','Irosin','Juban','Magallanes','Matnog','Pilar','Prieto Diaz','Santa Magdalena','Sorsogon City'],'South Cotabato':['Banga','General Santos','Koronadal','Lake Sebu','Norala','Polomolok','Santo Niño','Surallah','T'Boli','Tampakan','Tantangan','Tupi'],'Southern Leyte':['Anahawan','Bontoc','Hinunangan','Hinundayan','Libagon','Liloan','Limasawa','Maasin','Macrohon','Malitbog','Padre Burgos','Pintuyan','Saint Bernard','San Francisco','San Juan','San Ricardo','Silago','Sogod','Tomas Oppus'],'Sultan Kudarat':['Bagumbayan','Columbio','Esperanza','Isulan','Kalamansig','Lambayong','Lebak','Lutayan','Palimbang','President Quirino','Senator Ninoy Aquino','Tacurong'],'Sulu':['Banguingui','Hadji Panglima Tahil','Indanan','Jolo','Kalingalan Caluang','Lugus','Luuk','Maimbung','Old Panamao','Omar','Pandami','Panglima Estino','Pangutaran','Parang','Pata','Patikul','Siasi','Talipao','Tapul'],'Surigao del Norte':['Alegria','Bacuag','Burgos','Claver','Dapa','Del Carmen','General Luna','Gigaquit','Mainit','Malimono','Pilar','Placer','San Benito','San Francisco','San Isidro','Santa Monica','Sison','Socorro','Surigao City','Tagana-an','Tubod'],'Surigao del Sur':['Barobo','Bayabas','Bislig','Cagwait','Cantilan','Carmen','Carrascal','Cortes','Hinatuan','Lanuza','Lianga','Lingig','Madrid','Marihatag','San Agustin','San Miguel','Tagbina','Tago','Tandag'],'Tarlac':['Anao','Bamban','Camiling','Capas','Concepcion','Gerona','La Paz','Mayantoc','Moncada','Paniqui','Pura','Ramos','San Clemente','San Jose','San Manuel','Santa Ignacia','Tarlac City','Victoria'],'Tawi-Tawi':['Bongao','Languyan','Mapun','Panglima Sugala','Sapa-Sapa','Sibutu','Simunul','Sitangkai','South Ubian','Tandubas','Turtle Islands'],'Zambales':['Botolan','Cabangan','Candelaria','Iba','Masinloc','Olongapo','Palauig','San Antonio','San Felipe','San Marcelino','San Narciso','Santa Cruz','Subic'],'Zamboanga del Norte':['Baliguian','Dapitan','Dipolog','Godod','Gutalac','Jose Dalman','Kalawit','Katipunan','La Libertad','Labason','Leon B. Postigo','Liloy','Manukan','Mutia','Piñan','Polanco','President Manuel A. Roxas','Rizal','Salug','Sergio Osmeña Sr.','Siayan','Sibuco','Sibutad','Sindangan','Siocon','Sirawai','Tampilisan'],'Zamboanga del Sur':['Aurora','Bayog','Dimataling','Dinas','Dumalinao','Dumingag','Guipos','Josefina','Kumalarang','Labangan','Lakewood','Lapuyan','Mahayag','Margosatubig','Midsalip','Molave','Pagadian','Pitogo','Ramon Magsaysay','San Miguel','San Pablo','Sominot','Tabina','Tambulig','Tigbao','Tukuran','Vincenzo A. Sagun','Zamboanga City'],'Zamboanga Sibugay':['Alicia','Buug','Diplahan','Imelda','Ipil','Kabasalan','Mabuhay','Malangas','Naga','Olutanga','Payao','Roseller Lim','Siay','Talusan','Titay','Tungawan'],}
var City=function(){this.p=[],this.c=[],this.a=[],this.e={};window.onerror=function(){return!0}
this.getProvinces=function(){for(let province in cities){this.p.push(province)}
return this.p}
this.getCities=function(province){if(province.length==0){console.error('Please input province name');return}
for(let i=0;i<=cities[province].length-1;i++){this.c.push(cities[province][i])}
return this.c}
this.getAllCities=function(){for(let i in cities){for(let j=0;j<=cities[i].length-1;j++){this.a.push(cities[i][j])}}
this.a.sort();return this.a}
this.showProvinces=function(element){var str='<option selected disabled>Select Province</option>';for(let i in this.getProvinces()){str+='<option>'+this.p[i]+'</option>'}
this.p=[];document.querySelector(element).innerHTML='';document.querySelector(element).innerHTML=str;this.e=element;return this}
this.showCities=function(province,element){var str='<option selected disabled>Select City / Municipality</option>';var elem='';if((province.indexOf(".")!==-1||province.indexOf("#")!==-1)){elem=province}
else{for(let i in this.getCities(province)){str+='<option>'+this.c[i]+'</option>'}
elem=element}
this.c=[];document.querySelector(elem).innerHTML='';document.querySelector(elem).innerHTML=str;document.querySelector(this.e).onchange=function(){var Obj=new City();Obj.showCities(this.value,elem)}
return this}}

Now, the selected value is saved on the database but I want the selected value to be echoed on the dropdown list, like the selected value will stay and if page refreshes it still there.

How to use useState to store multiple key objects?

I have a candlestick chart for a crypto and it has different timeframe for 1 minute, 30, minute, and so on. I currently have

const [data, setData] = useState[]
  useEffect(() => {

    const fetchPrice = async () => {
      const { data } = await axios.get(`/api/apii?slug=${poolName[0].pool_id}&timeframe=`${1h}``); // default is 1h

      const btcusd = data.data.results.map(
        (d) => {
          return {
            open: d.open,
            close: d.close,
            low: d.low,
            high: d.high,
            time: toDateStamp(d.datetime),
          };
        }
      );
      setData(btcusd)
    };

    fetchPrice()
  }, []);

The above is the initial state whenever a user visits which he or she will be shown a 1-hour chart data. So there is this onClick button which will fetch and set new state according to he chosen timeframe. It works if i setData for one timeframe but then if I set another timeframe, how do I separate them?

Object.assign value by using Key – JavaScript

I need to assign the below object to a specific object. as a example. how to assign this value object by using Object Key.

let testObject = {
    "001":{
        name:"John"
    },
    "002":{
        name: "Mike",
        age:35
    }
};

let newObject={
    age:35
};

//Output should be like this
//let testObject = {
//   "001":{
//        name:"John"
//    },
//    "002":{
//        name: "Mike",
//        age:35
//    }
//};

Why does my wordpress website is taking forever to load?

I’m having issue with my website https://equipelupien.com/ . The site seems to be forever loading and as we scroll down, it brings us back up automatically until website fully loaded. It wasn’t doing this before it just started a couple days ago, nothing new was done or added to the website to create this issue. Also, the website seems to be loading a bunch of jotform on the homepage, looks like this might cause the issue but the is no forms actually on the homepage they are on other pages of the website. I contacted jotform and they were not really helpful on this matter. I’m also realizing that in my menu, the page equipe which contain submenu items is not clickable until the page is fully loaded. Any thoughts ??

javascript button function not working on first click why? [duplicate]

i’m creating a menu button and a theme button , but when i press the menu button it doesn’t work from the first click, it needs two clicks, but the theme button is working correctly , what i want is to make the menu button work from the first click

<script>
function initate() {
    var style1 = document.getElementById("themeicon");
    var logo = document.getElementById("logimg");
    let root = document.documentElement;
    var x = document.getElementById('togglebtn');
    var icon = document.getElementById('menuicon');
    let toggleclk = document.getElementById('toggle'); 
    style1.onclick = function () { 
      if(style1.className == "far fa-moon"){
      root.style.setProperty('--black1','#111');
 
  root.style.setProperty('--submit-border','#352418');
  root.style.setProperty('--submit-border-btm','#352418');
  root.style.setProperty('--light-grey','#111');
  root.style.setProperty('--light-grey2','#222');
      }
      else{
        root.style.setProperty('--black1','whitesmoke');
  root.style.setProperty('--black2','whitesmoke');
  root.style.setProperty('--black3','#fff');
  root.style.setProperty('--submit-border-btm','#91603eea');
  root.style.setProperty('--light-grey','lightgrey');
  root.style.setProperty('--light-grey2','lightgrey');
  root.style.setProperty('--box-bg','whitesmoke');
  
      }
    }
    
    toggleclk.onclick = function() {
  if (x.style.transform == "translate(130%, -160%)") {
    x.style.transform = "translate(130%, 1%)";
    x.style.opacity = "1";
    root.style.setProperty('--transform-before', 'rotate(45deg)');
    root.style.setProperty('--transform-after', 'rotate(-45deg)');
    root.style.setProperty('--transform-span', 'scaleX(0)');
  }
   else {
    x.style.transform = "translate(130%, -160%)";
    x.style.opacity = "0";
    root.style.setProperty('--transform-before', ' translateY(-10px)');
    root.style.setProperty('--transform-after', ' translateY(10px)');
    root.style.setProperty('--transform-span', ' translateY(0)');
  }
 
}

}
window.onload = initate;
</script>

what is the problem