I try to change the background color at on small app in html css js

I try to change the background color at on small app in html css js
one snap of this is:

var myoutput = document.getElementById("output");

function roundNum(){
AlphaValue=0.4;
RedValue=255;
GreenValue=0;
BlueValue=0;
outputColor=[RedValue,GreenValue,+BlueValue,AlphaValue];
return outputColor;
}
myColor=roundNum();
myColor1=myColor[0];
myColor2=myColor[1];
myColor3=myColor[2];
myColor4=myColor[3];
myoutput.style.backgroundColor ="( 
rgba("+myColor1+","+myColor2+","+myColor3+","+myColor4+");";

Javascript:: Looping thru multidimentional array of objects [duplicate]

I am looking for a proper way to extract all the array of objects thru simple loop.

let scores=
{
    ballet:
    {
        monica:     ["comments1","91"],
        yael:       ["comments2","79"],
    },
    swimming:
    {
        gabay:      ["comments3","82"],
        victor:     ["comments3","95"],
    },
    guitar:
    {
        gangina:    ["comments4","97"],
        diko:       ["comments5","42"],
    }
};

…as a side note since the real database is huge so performace is also an issue here 🙂

I was tring :

let index = 0;
while(index < scores.length){
  console.log(scores[index]);
  index += 1;
}

with no results 🙁

…and I thought it must be simple 🙂

Why cant I use jwt.verify() from jsonwebtoken in react?

When I use the function of jwt.verify() or jwt.decode() in react, it shows me a lot of errors.

The errors are:

ERROR in ./node_modules/jwa/index.js 5:13-30

Module not found: Error: Can’t resolve ‘crypto’ in ‘C:Usersclientnode_modulesjwa’

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
– add a fallback ‘resolve.fallback: { “crypto”: require.resolve(“crypto-browserify”) }’
– install ‘crypto-browserify’
If you don’t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { “crypto”: false }

ERROR in ./node_modules/jwa/index.js 9:11-26

Module not found: Error: Can’t resolve ‘util’ in ‘C:Usersclientnode_modulesjwa’

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
– add a fallback ‘resolve.fallback: { “util”: require.resolve(“util/”) }’
– install ‘util’
If you don’t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { “util”: false }

ERROR in ./node_modules/jws/lib/data-stream.js 4:13-30

Module not found: Error: Can’t resolve ‘stream’ in ‘C:Usersclientnode_modulesjwslib’

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
– add a fallback ‘resolve.fallback: { “stream”: require.resolve(“stream-browserify”) }’
– install ‘stream-browserify’
If you don’t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { “stream”: false }

ERROR in ./node_modules/jws/lib/data-stream.js 6:11-26

Module not found: Error: Can’t resolve ‘util’ in ‘C:Usersclientnode_modulesjwslib’

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
– add a fallback ‘resolve.fallback: { “util”: require.resolve(“util/”) }’
– install ‘util’
If you don’t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { “util”: false }

ERROR in ./node_modules/jws/lib/sign-stream.js 8:13-30

Module not found: Error: Can’t resolve ‘stream’ in ‘C:Usersclientnode_modulesjwslib’

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
– add a fallback ‘resolve.fallback: { “stream”: require.resolve(“stream-browserify”) }’
– install ‘stream-browserify’
If you don’t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { “stream”: false }

ERROR in ./node_modules/jws/lib/sign-stream.js 12:11-26

Module not found: Error: Can’t resolve ‘util’ in ‘C:Usersclientnode_modulesjwslib’

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
– add a fallback ‘resolve.fallback: { “util”: require.resolve(“util/”) }’
– install ‘util’
If you don’t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { “util”: false }

ERROR in ./node_modules/jws/lib/verify-stream.js 8:13-30

Module not found: Error: Can’t resolve ‘stream’ in ‘C:Usersclientnode_modulesjwslib’

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
– add a fallback ‘resolve.fallback: { “stream”: require.resolve(“stream-browserify”) }’
– install ‘stream-browserify’
If you don’t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { “stream”: false }

ERROR in ./node_modules/jws/lib/verify-stream.js 12:11-26

Module not found: Error: Can’t resolve ‘util’ in ‘C:Usersclientnode_modulesjwslib’

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
– add a fallback ‘resolve.fallback: { “util”: require.resolve(“util/”) }’
– install ‘util’
If you don’t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { “util”: false }

NOTE: I try to do the recomendations that the errros say, but it dont fixes it

setTimeOut not working in recursive function

I am creating a sorting visualizer. For iterative sorting algorithms, my code works perfectly but for quick sort and merge sort it does not. The function does not wait and immediately returns output but I have to show changes slowly by animations.Following is my code.

const delay = (time) => {
    return new Promise((resolve) => setTimeout(resolve, time));
  };
const quickSortHelper = async(arr, a, b) => {
    if (b > a) {
      document.getElementById(a).style.backgroundColor="green"
      let pivot = getPivot(arr, a, b)
      await delay(2*animationSpeed)
      setArray([...arr])
      document.getElementById(a).style.backgroundColor="#343434"
      await delay(2*animationSpeed)
      quickSortHelper(arr, a, pivot - 1)
      await delay(4*animationSpeed)
      quickSortHelper(arr, pivot + 1, b)
    }
  }
  const quickSort = () => {
    setStartSorting(true)
    let arr = [...array]
    console.log(arr);
    quickSortHelper(arr, 0, arr.length - 1)
    console.log('ended');
    setStartSorting(false)
  }
  const getPivot = (arr, a, b) => {
    let pivot = arr[a]
    var i = a
    var j = b
    while (j > i) {
      while (pivot >= arr[i] && i<=b) {
        i++
      }
      while (pivot < arr[j] && j>=a) {
        j--
      }
      if (j > i) {
        let temp = arr[i]
        arr[i] = arr[j]
        arr[j] = temp
      }
    }
    let temp =pivot
    arr[a] = arr[j]
    arr[j] = temp
    return j
  }
 

The console.log(‘ended’) is executed immediately as soon as I run the function and states are also updated immediately.

How to access elements in PDF rendered on Microsoft Edge?

I am using a selenium script to access elements on PDF rendered on MS Edge.
Even though I can see the elements while inspecting the page like

<div id="layout-container" style="opacity: 1; width: 826px; height: 1066px; top: 45px; transform: scale(1) translate(346px, 0px);"><div class="pagerect" id="pagediv_0" style="left: 5px; top: 3px; width: 816px; height: 1056px;"></div></div>

My script is unable to access them using all sorts of ways in selenium, waiting for elements to render etc

I have even tried executing JS snippet to try and access them and the script return no results even though the same script works in Console of dev tools.
Like

document.querySelector("#layout-container")

This works in the Console but not when executing.

I am using Selenium with Python so solutions on that will be preferred.

jQuery? checking if IP address are within the range

I want to be able to check that two IP address are within the range. So if a user enter something like 10.10.10.0 and 10.10.10.10 then it will pass the validation and enter that address into the database. Then want to check if a users enter something like 10.9.10.10 that would be invalid and I would ask the user to correct the error. My thinking is that I would convert the IP address into long and then make sure the endIpAddrToLong is greater then the startIpAddrToLong

Is this the correct Logic to do something like that? Can I just convert the IP’s to longs and compare them

    $('#button-validate').on('click', function() {
       let startIpAddr = $("#txtstartIpAddr").val();
       var startIpAddrToLong = parseInt(IpAddressToLong(startIpAddr));
       
       let endIpAddr = $("#txtendIpAddr").val();
       var endIpAddrToLong = parseInt(IpAddressToLong(endIpAddr));
      
       if (endIpAddrToLong >  startIpAddrToLong) {
            console.log('success');
          $("#validate").val("True");
        }
       
    });
    
    function IpAddressToLong(ip){
            return ip.split('.').map((octet, index, array) => {
        return parseInt(octet) * Math.pow(256, (array.length - index - 1));
            }).reduce((prev, curr) => {
        return prev + curr;
        });

}

working sample
http://jsfiddle.net/tjmcdevitt/mdkx9h0w/31/

is it possible to make sass-loader using dart-sass not node-sass

Because the node-sass have a big install problem and compatible problem, I do not want to use node-sass, prefer to use dart sass in my project. But when I use the sass-loader like this:

"sass-loader": "7.0.0",

shows that:

  ERROR in ./node_modules/sass-loader/lib/loader.js!./node_modules/css-loader?sourceMap!./node_modules/sass-loader/lib/loader.js?sourceMap!./src/public/widget/style.scss
    Module build failed: Error: `sass-loader` requires `node-sass` >=4. Please install a compatible version.
        at Object.sassLoader (/Users/xiaoqiangjiang/source/reddwarf/frontend/crx-selection-translate/node_modules/sass-loader/lib/loader.js:31:19)
     @ ./node_modules/style-loader!./node_modules/sass-loader/lib/loader.js!./node_modules/css-loader?sourceMap!./node_modules/sass-loader/lib/loader.js?sourceMap!./src/public/widget/style.scss 4:14-197

what should I do to let the sass-loader ignore the node sass and use dart sass? I hate node sass, it waste too much time to handle the install and compatible problem. BTW, this is my project package.json content:

{
  "private": true,
  "repository": {
    "type": "git",
    "url": "git+https://github.com/jiangxiaoqiang/crx-selection-translate.git"
  },
  "scripts": {
    "xpostinstall": "node ./build/install-pdf-viewer",
    "dev": "webpack --config build/webpack.dev.config.js",
    "build": "gulp --cwd . --gulpfile build/gulp-build.js",
    "test": "karma start build/karma.config.js"
  },
  "dependencies": {
    "bootstrap-sass": "^3.4.1",
    "chrome-call": "^1.0.2",
    "connect.io": "^3.1.3",
    "interact.js": "^1.2.6",
    "js-wheel": "https://github.com/jiangxiaoqiang/js-wheel.git",
    "translation.js": "github:jiangxiaoqiang/translation.js",
    "vue": "^1.0.24",
    "vue-router": "^0.7.11"
  },
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^6.2.4",
    "babel-plugin-transform-runtime": "^6.9.0",
    "babel-polyfill": "^6.9.1",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-stage-3": "^6.5.0",
    "chrome-env": "^0.0.6",
    "css-loader": "^0.23.1",
    "del": "^2.2.0",
    "download": "^5.0.0",
    "extract-text-webpack-plugin": "^3.0.2",
    "file-loader": "^0.8.5",
    "fs-extra": "^8.1.0",
    "gulp": "^3.9.1",
    "gulp-clean-css": "^2.3.2",
    "gulp-htmlmin": "^2.0.0",
    "gulp-jsonmin": "^1.2.0",
    "gulp-uglify": "^1.5.3",
    "gulp-zip": "^3.2.0",
    "isparta-loader": "^2.0.0",
    "jasmine-core": "^2.99.1",
    "karma": "^6.3.11",
    "karma-chrome-launcher": "^1.0.1",
    "karma-coverage": "^2.1.0",
    "karma-coveralls": "^2.1.0",
    "karma-firefox-launcher": "^1.3.0",
    "karma-ie-launcher": "^1.0.0",
    "karma-jasmine": "^1.1.2",
    "karma-phantomjs-launcher": "^1.0.0",
    "karma-safari-launcher": "^1.0.0",
    "karma-sourcemap-loader": "^0.3.8",
    "karma-webpack": "^1.7.0",
    "phantomjs-prebuilt": "^2.1.6",
    "raw-loader": "^0.5.1",
    "sass": "1.48.0",
    "sass-loader": "7.0.0",
    "style-loader": "^0.13.0",
    "vue-html-loader": "^1.2.0",
    "webpack": "^3.12.0",
    "webpack-cli": "^4.9.1"
  },
  "author": "Jiangxiaoqiang <[email protected]>",
  "license": "GPLv3",
  "bugs": {
    "url": "https://github.com/jiangxiaoqiang/crx-selection-translate/issues"
  },
  "homepage": "https://github.com/jiangxiaoqiang/crx-selection-translate#readme"
}

Uncaught ReferenceError: GetCountOfPeople is not defined at HTMLButtonElement.onclick (GetCountOfPeople:1)

I am getting

Uncaught ReferenceError: GetCountOfPeople is not defined  at HTMLButtonElement.onclick (GetCountOfPeople:1)

Not sure what am i doing wrong.

export function GetCountOfPeople (LocationGuid) {
    'use strict';
    try {
        console.log('Called GetCountOfPeople');
    } catch (e) {
        console.error("Error Occured in GetCountOfPeople  Method");
    }
}

This button is rendered like this when inspecting in developer tools, element inspector

<button class="btn btn-success mt-2" onclick="GetCountOfPeople('e28e06b4-6434-44fa-812b-d86e2c061bce')" tabindex="0">GetCountOfPeople Here</button>

This button is generated from the following code

var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker, 'click', (function (marker) {
                return function () {
                    InfocusMarker = marker;

                    var content = "<span style='font-weight: bold;'>" + marker.LocationName + "</span>"
                        content = content + "<br/><button class='btn btn-success mt-2' onclick=GetInLine('" + marker.LocationGuid + "')>GetInLine Here</button>"

                    }

                    infowindow.marker = marker;
                    infowindow.setContent(content);
                    infowindow.open(mapNew, marker);
                }
            })(marker, i));

How to initialize to an empty array if my ‘students’ parameter is not passed

I am attempting to write code For the Bootcamp class (as shown in the code block) My goal is to write the code for the Bootcamp class so that if it the “students” parameter is not passed in, it is by default initialized to be an empty array from within the constructor parameter list itself. i took a stab at it with the function at the bottom of the code.

I am a bit confused regrading the proper syntax. Please See my Code Below

  • Thank you in advance 🙂
class Bootcamp{
    constructor(name,level,students){
        this.name = name;
        this.level = level;
        this.students = students;
    }
}
function student (students){
    return [];
} 

DOMContentLoaded and click event don’t occur

I have a spring boot application with thymeleaf.

I have an input box with a button. When I click on it, I do an ajax call and return a thymeleaf fragment.

I do this ajax call with this code in a fragment

    <script type="text/javascript" th:inline="javascript">

        document.addEventListener('DOMContentLoaded', function () {
            console.log("DOMContentLoaded");

            let searchAdsForm = document.getElementById("searchAdsForm")

            searchAdsForm.addEventListener("submit", function(event) {

                event.preventDefault();

                let jsonSearchAdsForm = FormDataJson.toJson(searchAdsForm)
                let urlParams = new URLSearchParams(jsonSearchAdsForm).toString();
                let url = "/findads?" + urlParams;

                fetch(url, {
                    method: "get"
                }).then(result => {
                    if (result.status != 200) {
                        throw new Error("Bad Server Response");
                    }
                    return result.text();

                }).then((content) => {
                    document.getElementById("main").innerHTML = content;
                }).catch((error) => {
                    console.log(error);
                });


            }, false);

        }, false);

        window.addEventListener('load', function () {
            console.log("full load page");
        }, false);

    </script>

It return a table of result. It’s displayed without problem.

Code who return fragment.

@GetMapping("/findads")
public String findAdsBy(Model model, @RequestParam(name="itemToSearch") String search){
    System.out.println(search);

    Flux<Ads> ads  = service.findAds(search);

    IReactiveDataDriverContextVariable data = new
                ReactiveDataDriverContextVariable((ads));
    model.addAttribute("ads", data);

    return "fragments/resultsearch::resultSearch";
}

Fragment returned

<div th:fragment="adsResultSearch" class="tabsearch">

    <table class="table table-striped">
      <tr>
       <th scope="col">Donateur</th>
       <th scope="col">Titre</th>
      </tr>
      <tr th:each="ad : ${ads}">
            <td><a href="#" th:attr="data-donor=${ad.donor}" th:text="${ad.donor}"/></td>
            <td th:text="${ad.title}"></td>
        </tr>
    </table>

    <script type="text/javascript" inline="javascript">
        console.log("js");
        document.addEventListener('DOMContentLoaded', function () {
            console.log("dom ready");
        });

        document.addEventListener('click', function (event) {
            console.log("click");
        });

    </script>

It’s like the javascript of the fragment return is never running.

Endpoint URL not found in axios PUT endpoint

When pressing a button, my app is suppose to subtract 1 from the current Quantity in the database where the name of the item is “CrossBag”

My PUT endpoint on the client:

confirm = () => {
    axios.put(`http://localhost:5000/merch/CrossBag`, {
        Quantity: this.state.merchInfo[0].Quantity - 1,
        });
};

The structure of my table merch where Name is the primary key:
enter image description here

The server side of the endpoint:

app.put('/merch', function (req, res) {

  connection.getConnection(function (err, connection) {

  if(err) 
  {
    console.log(err)
    return
  }

});
});

When I press the button though it states:

PUT http://localhost:5000/merch/CrossBag 404 (Not Found)

I’m a bit confused on how to update specifically that row’s Quantity. I read that you need some kind of ID to specify which row to change, so I made that ID my Primary Key (Name).

Can anyone provide me any guidance?

add url before output taken from javascript

I want to add a URL before the javascript output, basically, I want to enter the URL from the input field and my javascript convert it into Base64 and show it in the output box but problem is that I want to add URL as default before my base64 encoded code. Like below

User input: https://google.com
User Output (Base64): asdweoiuweosdj

But I want this

User Input:  https://google.com
User Output: https://example.com?=asdweoiuweosdj

<!DOCTYPE html>
<html>

<body>

  <div id="container">
    <div class="IO-field">
      <input type="text" id="plain-text">
      <button type="button" onclick="getInputValue();" id="text-submit">click</button>
      <input class="text" id="base-64">
    </div>


    <script>
      var plainTextIOField = document.querySelector("#plain-text"),
        base64IOField = document.querySelector("#base-64"),
        textSubmit = document.querySelector("#text-submit"),


        //use the index of each character in the array as the key that links value and corresponding char in base64 table  
        base64Table = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
          "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
          "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/"
        ];


      //function that converts a standard ASCII character decimal value into its binary correspondant and turns it into a string
      function dec2bin(dec) {
        var bin = (dec >>> 0).toString(2);
        if (bin.length < 8) {
          var itrs = 8 - bin.length;
          for (var i = 0; i < itrs; i++) {
            bin = "0" + bin;
          }
        }
        return bin;
      }


      textSubmit.addEventListener("click", function(e) {

        //block browser form reloading the page
        e.preventDefault();

        //declare variables needed during the conversion
        var string = plainTextIOField.value,
          stringToArray = string.split(''),
          s = "",
          array64 = [];

        //for each letter in the stringToArray array get its charCode, convert it to binary form, make it a string and concatenate it with the s string
        for (var i = 0; i < stringToArray.length; i++) {

          var charCode = stringToArray[i].charCodeAt(0);
          s += dec2bin(charCode);

        }

        //make s an array made of each bit represented in the s string
        s = s.split('');


        //put all the strings of the s array inside array64 and separate each series of 6 consecutive elements with a single whitespace
        for (var i = 0; i < s.length; i++) {

          if (i > 0 && i % 6 === 0)
            array64.push(" ");
          array64.push(s[i]);

        }

        //concatenate all of array64's elements into a single string and then break the string using the whitespaces just added as divider
        array64 = array64.join('').split(' ');


        //make sure each string representing a binary value in array64 is 6 chars long
        if (array64[array64.length - 1].length < 6) {

          var array64Last = array64.pop(),
            nOf0s = 6 - array64Last.length;

          for (var i = 0; i < nOf0s; i++) {

            array64Last += "0";

          }

          array64.push(array64Last);

        }


        //make sure the array64's length is a multiple of 4, and if not add correct padding as base64 encoding requires
        if (array64.length % 4 !== 0) {

          var padding = 4 - (array64.length % 4);

          for (var i = 0; i < padding; i++) {

            array64.push("=");

          }

        }


        //substitute each string in array64 with its corresponding binary value and then with the value get the right character from the base 64 table
        for (var i = 0; i < array64.length; i++) {
          if (array64[i] == "=") {
            continue;
          }
          array64[i] = base64Table[parseInt(array64[i], 2)];
        }

        //concatenate all the characters inside of array64 and done :D
        base64IOField.value = array64.join('');

      })
    </script>

</body>

</html>

Please Help I am very confused about it. I am a beginner in javascript