Javascript Testing with a loop

I have quite a number of constants which I am importing with import.

Would it be considered bad practice to loop thru them and check that certain things match up when testing?

import * as allCommunicationExports from '../public/communication.min';
for (const [communicationSelectorConstant, value] of Object.entries(allCommunicationExports)) {
        it(`should have a constant named ${ communicationSelectorConstant } is a string and starts with a selector for a data attribute`, () => {
            expect(allCommunicationExports[communicationSelectorConstant]).toBeDefined();
            expect(typeof allCommunicationExports[communicationSelectorConstant]).toBe('string');
            expect(allCommunicationExports[communicationSelectorConstant].startsWith('[data-js-comms')).toBeTruthy();
            // more to come
        });
    }

Is there a possibility with javascript to show a scroll hint only at the first pageload?

I have created a simple scroll hint which disappears by mousedown. My goal is that the hint is only displayed the first time. When I reload the page, it should not be displayed again. Only again when the cache of the web page is cleared.

Is there a simple way to realise it with javascript?

Here is my code html code:

<div id="content" onmousedown="hideHint()">
  <div id="scroll-hint" >
    <div class="mouse">
        <span></span>
    </div>
  </div>
</div>

Here is my css:

body{
    margin: 0;
  }

  #content{
    background-color: orange;
    height: 100vh;
    width: 100vw;
  }

  #scroll-hint{
  background-color: gray;
  border-style: solid;
  height: 20vh;
  width: 20vw;
  align-items: center;
  display: flex;
  justify-content: center;
  position: fixed;
  left: 40%;
  }

  .mouse {
      display: block;
      width: 23px;
      height: 40px;
      border-radius: 13px;
      border: 2px solid blue;
      position: absolute;
      left: 50%;
      margin: 0 auto 0 -14px;
      background-color: white;
  }


  span {
      display: block;
      margin: 6px auto;
      width: 3px;
      height: 7px;
      border-radius: 100%;
      background: blue;
  }

And here is my javascript:

function hideHint() {
    document.getElementById("scroll-hint").style.display = "none";
  }

user not defined for onAuthStateChanged in Firebase with custom hook

I built a custom hook to get a user from firebase:

export function useAuth() {
  const [currentUser, setCurrentUser] = useState<any>();

  useEffect(() => {
    const unsubscribe = onAuthStateChanged(auth, async (user) => {
      if (user === null) {
        setCurrentUser(null);
      } else {
        const u = await getDoc(doc(db, "users", user.uid));
        const name = u.data().name;
        setCurrentUser(user === null ? null : { ...user, name: name });
      }
    });
    return unsubscribe;
  }, []);

  return currentUser;
}

In my components I use it as:

const currentUser = useAuth();
useEffect(() => {
    const localScore = JSON.parse(localStorage.getItem("score"));
    setPush(!(localScore[currentUser.name] === tasks.length));
                                  // ^ TypeError: Cannot read properties of undefined (reading 'name')
  }, []);

I think I get the error, because when the components gets rendered the first time, there is no currentUser. But I load the component after the user logged in (what sets the user), thus I am confused.

I think I need to await the user somehow, but how?

What causes Chrome Performance Tools occupying an immense amount of CPU when web workers are involved?

The problem I’m having can be boiled down to this:

The setup

There are two files: index.html and worker.js.

In index.html:

<script>
foo = new Worker("worker.js");
</script>

Worker.js contains no code in this example. In my actual code, the worker will wait for messages, but the only important part here is that it is not killed.

The problem

When I now go to the Performance tab within Chrome Dev Tools, and hit “Start profiling and reload page”. The workers will persistently use an immense amount of CPU time, even after the profiling has finished. That amount can be as high as 100% core utilization per worker.

The problem scales with the number of web workers and as soon as I kill them, the utilization stops. So I can be sure, that it is indeed the workers who cause this problem.

My questions

  • What causes this behaviour? Does the profiler inject some code into the workers themselves, which is not removed after the profiling finished?
  • What can I do about it?
  • Can I maybe somehow turn off the profiling for web workers while profiling my webapp?

This problem might sound minor, since it only happens when profiling and not on the users PCs, but my app uses as many web workers as the client has CPU cores, who all wait for jobs instructions. While debugging profiling that utilizes 100% of my CPU. And as I said, after profiling has finished, it doesn’t stop. I don’t want to kill the workers via console, every time I profile my app. I also don’t want to have my CPU run at 100% for hours when I forget to kill the workers after profiling and leaving the PC.

Changing my app, so that the workers are started and killed per job is not an option.

AppScript Problem using GmailApp.SendEmail function

Background:
I’m currently taking a Visual Programming class where we use Google Sheet/ AppScript to create a simple system using triggers and function.

Problem: I’m trying to mimic and create a simple online ordering system where it will send emails to customers once our “restaurant” receives, preparing and delivering their order using GmailApp.SendEmail function. I put some functions on the AppScript but I just cant get what I want to do in code. Here is what I have so far: ( I created a custom menu for each function. For example, once “Preparing Order” button is clicked, the customer will receive an email stating that their order is being prepared”

function prepareOrder(){

// send msge to customer that a Kitchen is preparing the order
// 


}

function completedOrder() {
// send msge to customer that the Kitchen has completed the order 
// 
}

function readyForDelivery()
{
// send msge to customer that the delivery person is preparing the order for delivery 
// 
// 
}

function deliveredOrder() {
// send msge to customer that the order has been delivered and completed with a receipt
//
//  
} 

Goal: As mentioned before, Im a beginner at this and my path is probably silly but my goal is to somehow automate and grab customer info (email) from the spreadsheet to then use that information to send an email and create a receipt/invoice of their order.

AppScipt_SS

Spreadsheet_SS

Integrating multiple analytics libraries in my web app

I have to integrate multiple tracking libraries for ex: (Exponea, Azure Application insights)
One is a marketing tracking SDK and another is a general tracking sdk used for getting general metrics, will also be integrating another tracking sdk (ex: Google Analytics) for a different purposes.

Because of the above, I might have to include other libraries in the future, Just want to know is there any industry-standard way to implement the above And also make these libraries loosely couple with my application?

I have gone through Google Tag manager, wherein I can configure which page can load 3rd party sdk, which looks okie, but not sure about the other advantages I would get out of it. Once integrated i don’t require any code change if i want to add a new event to my web app?

Thoughts?

Looking for Javascript code to ignore the outliers value provided to it during input

I want to try the The tests in test/average.test.js express the functionality of the average function.
Consider this situation: In IoT applications, analog sensors will report occasional outliers. ‘Outliers’ are values so small or so large, they aren’t expected to happen. We need new functionality to ignore these outliers.
I’ll need thresholds to recognize outliers: Think of sensing battery-temperature values and determine reasonable values.

heres the code for average.test.js:-

const {expect} = require('chai');
const {average} = require('../average');

it('computes average of a list of numbers', ()=> {
  // floating point numbers cannot be compared for equality,
  // hence allowing a delta tolerance
  expect(average([1, 2, 3, 4])).to.be.approximately(2.5, 0.01);
});

it('reports the average as NaN on an empty list', ()=> {
  expect(average([])).to.be.NaN;
});

it('ignores NaN in the input', ()=> {
  expect(average([1, NaN, 2])).to.be.approximately(1.5, 0.01);
});

And Heres the code for average.js file :-

function average(numbers) {
  
  //Used Filter Function to clear out any Garbage inputs.
   numbers=numbers.filter(Boolean);
   return numbers.reduce((p, c)=> p + c, 0) / numbers.length;
}

module.exports = {average};

How to repeat this 2 sections on HTML above on every printed page Safari?

I would like to repeat this 2 section here on every printed page on Safari. I try many ways but on Safari it just won’t repeat the header on every printed pages. Safari just skip the header and continue on print. Some solution works on Chrome but not on Safari.
Any idea how to repeat these 2 header sections on every printed page ?

Header 1

Header 2

Here the html code for the

<!DOCTYPE html>
<html>
   <head>
      <meta content="text/html; charset=utf-8" http-equiv="content-type">
      <title>A simple, clean, and responsive HTML invoice template</title>
      <style>
         /* THE FOLLOWING CSS IS REQUIRED AND SHOULD NOT BE MODIFIED. */
         div.fauxRow {
         display: inline-block;
         vertical-align: top;
         width: 100%;
         page-break-inside: avoid;
         }
         table.fauxRow {border-spacing: 0;}
         table.fauxRow > tbody > tr > td {
         padding: 0;
         overflow: hidden;
         }
         table.fauxRow > tbody > tr > td > table.print {
         display: inline-table;
         vertical-align: top;
         }
         table.fauxRow > tbody > tr > td > table.print > caption {caption-side: top;}
         .noBreak {
         float: right;
         width: 100%;
         visibility: hidden;
         }
         .noBreak:before, .noBreak:after {
         display: block;
         content: "";
         }
         .noBreak:after {margin-top: -594mm;}
         .noBreak > div {
         display: inline-block;
         vertical-align: top;
         width:100%;
         page-break-inside: avoid;
         }
         table.print > tbody > tr {page-break-inside: avoid;}
         table.print > tbody > .metricsRow > td {border-top: none !important;}
         /* THE FOLLOWING CSS IS REQUIRED, but the values may be adjusted. */
         /* NOTE: All size values that can affect an element's height should use the px unit! */
         table.fauxRow, table.print {
         font-size: 16px;
         line-height: 20px;
         }
         /* THE FOLLOWING CSS IS OPTIONAL. */
         body {counter-reset: t1;} /* Delete to remove row numbers. */
         .noBreak .t1 > tbody > tr > :first-child:before {counter-increment: none;} /* Delete to remove row numbers. */
         .t1 > tbody > tr > :first-child:before { /* Delete to remove row numbers. */
         display: block;
         text-align: right;
         counter-increment: t1 1;
         content: counter(t1);
         }
         table.fauxRow, table.print {
         font-family: Tahoma, Verdana, Georgia; /* Try to use fonts that don't get bigger when printed. */
         margin: 0 auto 0 auto; /* Delete if you don't want table to be centered. */
         }
         table.print {border-spacing: 0;}
         table.print > * > tr > * {
         border-right: 2px solid black;
         border-bottom: 2px solid black;
         padding: 0 5px 0 5px;
         }
         table.print > * > :first-child > * {border-top: 2px solid black;}
         table.print > thead ~ * > :first-child > *, table.print > tbody ~ * > :first-child > * {border-top: none;}
         table.print > * > tr > :first-child {border-left: 2px solid black;}
         table.print > thead {vertical-align: bottom;}
         table.print > thead > .borderRow > th {border-bottom: none;}
         table.print > tbody {vertical-align: top;}
         table.print > caption {font-weight: bold;}
         @media print
         {
         thead {display: table-header-group;}
         }
         #imageContainter {
         width: 80px;
         height: 80px;
         text-align: center;
         }
         .objectImg{
         max-width: 100%;
         max-height: 100%;
         /*object-fit: contain;
         object-fit: scale-down;
         object-position: -10% 0;
         object-fit: none;
         object-fit: fill;*/
         }
         .invoice-box{
         max-width:800px;
         margin:auto;
         padding:30px;
         /border:1px solid #eee;/
         /*box-shadow:0 0 10px rgba(0, 0, 0, .15); */
         font-size:15px;
         line-height:24px;
         font-family:'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif;
         color:#555;
         }
         .invoice-box table{
         width:100%;
         line-height:inherit;
         text-align:left;
         }
         .invoice-box table td{
         padding:2.5px;
         vertical-align:top;
         }
         .invoice-box table tr td:nth-child(2){
         text-align:right;
         }
         .invoice-box table tr.top table td{
         padding-bottom:20px;
         }
         .invoice-box table tr.top table td.title{
         font-size:45px;
         line-height:45px;
         color:#333;
         }
         .invoice-box table tr.top table th.orderTitle{
         text-align:right;
         padding-top:0px;
         padding-bottom:0px;
         }
         .invoice-box table tr.top table td.orderInfo{
         text-align:left;
         padding-top:0px;
         padding-bottom:0px;
         min-width: 20px;
         max-width: 150px;
         word-wrap: break-word;
         }
         .invoice-box table tr.top table th.addressTitle{
         font-size:14px;
         text-align:left;
         padding-top:0px;
         padding-bottom:0px;
         min-width: 20px;
         max-width: 150px;
         word-wrap: break-word;
         }
         .invoice-box table tr.top table td.addressInfo{
         text-align:left;
         padding-top:0px;
         padding-bottom:0px;
         padding-left:0px;
         min-width: 20px;
         max-width: 150px;
         word-wrap: break-word;
         }
         .invoice-box table tr.information table th.addressTitle{
         text-align:left;
         padding-top:0px;
         padding-bottom:0px;
         padding-left:0px;
         min-width: 20px;
         max-width: 150px;
         word-wrap: break-word;
         }
         .invoice-box table tr.information table td.addressInfo{
         text-align:left;
         padding-top:0px;
         padding-bottom:0px;
         padding-left:0px;
         min-width: 20px;
         max-width: 150px;
         word-wrap: break-word;
         }
         .invoice-box table tr.heading td{
         background:#eee;
         border-bottom:1px solid #ddd;
         font-weight:bold;
         }
         .invoice-box table tr.details td{
         padding-bottom:20px;
         }
         .invoice-box table tr.item td{
         border-bottom:1px solid #eee;
         }
         .invoice-box table tr.item.last td{
         border-bottom:none;
         }
         .invoice-box table tr.total td:nth-child(2){
         border-top:2px solid #eee;
         font-weight:bold;
         }
         thead.report-header {
         display:table-header-group;
         }
         @media only screen and (max-width: 600px) {
         .invoice-box table tr.top table td{
         width:100%;
         display:block;
         text-align:center;
         }
         .invoice-box table tr.information table td{
         width:100%;
         display:block;
         text-align:center;
         }
         }
      </style>
   </head>
   <body>
      <thead>
         <div class="invoice-box">
            <table cellpadding="0" cellspacing="0" border="0" >
               <tbody>
                  <td colspan="9">
                     <table >
                        <tbody>
                           <tr>
                              <th style="text-align:center;font-size:16px;">Testing</th>
                           </tr>
                        </tbody>
                     </table>
                  </td>
                  <tr class="top">
                     <td colspan="4">
                        <table cellpadding="0" cellspacing="0" style="border-collapse:collapse;" border="0" >
                           <tbody>
                              <tr>
                                 <th class="addressTitle">Testing Company</td>
                              </tr>
                              <tr>
                                 <td class="addressInfo">Testing Company <br>Testing Company <br>Testing Company <br>Testing Company </td>
                              </tr>
                           </tbody>
                        </table>
                     </td>
                  </thead>
                  <td colspan="6">
                     <table cellpadding="0" cellspacing="0" style="border-collapse:collapse;" border="0">
                        <tbody>
                           <tr>
                              <th class="orderTitle">Testing: </th>
                              <td class="orderInfo"> NULL </td>
                           </tr>
                           <tr>
                              <th class="orderTitle">Testing : </th>
                              <td class="orderInfo"> Testing Company </td>
                           </tr>
                           <tr>
                              <th class="orderTitle">Testing : </th>
                              <td class="orderInfo"> Testing Company  </td>
                           </tr>
                           <tr>
                              <th class="orderTitle">Testing : </th>
                              <td class="orderInfo">Testing Company  </td>
                           </tr>
                           <tr>
                              <th class="orderTitle">Testing : </th>
                              <td class="orderInfo">Testing Company  </td>
                           </tr>
                           <tr>
                              <th class="orderTitle">Testing: </th>
                              <td class="orderInfo">Testing Company  </td>
                           </tr>
                        </tbody>
                     </table>
                  </td>
                  </tr>
                  <tr >
                     <td colspan="9">
                        <hr/>
                     </td>
                  </tr>
                  <tr class="information">
                     <td colspan="4" >
                        <table>
                           <tbody>
                              <tr>
                                 <th style="text-align: left;background:#eee;"> BILL TO </th>
                              </tr>
                              <tr>
                                 <th class="addressTitle" style="text-align:left;"> Testing Company </th>
                              </tr>
                              <tr>
                                 <td class="addressInfo" style="text-align: left; padding:0px;"> Testing Company <br>Testing Company <br>Testing Company  <br>Testing Company </td>
                              </tr>
                           </tbody>
                        </table>
                     </td>
                     <td colspan="6">
                        <table>
                           <tbody>
                              <tr>
                                 <th style="text-align: left;background:#eee;"> SHIP TO </th>
                              </tr>
                              <tr>
                                 <th class="addressTitle" style="text-align:left;"> Testing Company  </th>
                              </tr>
                              <tr>
                                 <td class="addressInfo"  style="text-align: left;padding:0px;"> Testing Company ,<br>Testing Company <br>Testing Company<br>Testing Company  </td>
                              </tr>
                           </tbody>
                        </table>
                     </td>
                  </tr>
                  <tr class="heading">
                     <td style="text-align:left;width:3%;"> Testing </td>
                     <td style="text-align:left;width:20%;"> Testing </td>
                     <td style="text-align:left;width:15%;"> Testing </td>
                     <td style="text-align:left;width:40%;"> Testing </td>
                     <td style="text-align:center;width:12%;"> Testing  </td>
                     <td style="text-align:center;width:15%;"> Testing </td>
                     <td style="text-align:center;width:10%;"> Testing </td>
                     <td style="text-align:center;width:10%;"> Testing </td>
                     <td style="text-align:center;width:10%;"> Testing </td>
                  </tr>
                  <tr class="heading">
                     <td colspan="1"></td>
                     <td style="text-align:left;width:20%;"> Testing </td>
                     <td colspan="1"></td>
                     <td style="text-align:left;width:40%;"> Testing </td>
                     <td colspan="5" >
                     </td>
                  </tr>
                  <tr >
                     <td colspan="9" >
                  <tr class="item last">
                  <tr>
                     <td style="text-align: center;">1.</td>
                     <td style="text-align: left;">Testing</td>
                     <td>
                        <div id="imageContainter"> <img class="objectImg" src=''></div>
                     </td>
                     <td style="text-align: left;">Testing </td>
                     <td style="text-align: center;">3 </td>
                     <td style="text-align: center;">1050.00</td>
                     <td style="text-align: center;"></td>
                     <td style="text-align: center;word-wrap:break-word;">30%</td>
                     <td style="text-align: right;">2205.00</td>
                  <tr>
                  <tr>
                     <td style="text-align: center;">1.</td>
                     <td style="text-align: left;">Testing</td>
                     <td>
                        <div id="imageContainter"> <img class="objectImg" src=''></div>
                     </td>
                     <td style="text-align: left;">Testing </td>
                     <td style="text-align: center;">3 </td>
                     <td style="text-align: center;">1050.00</td>
                     <td style="text-align: center;"></td>
                     <td style="text-align: center;word-wrap:break-word;">30%</td>
                     <td style="text-align: right;">2205.00</td>
                  <tr>          
                  <tr>
                     <td style="text-align: center;">1.</td>
                     <td style="text-align: left;">Testing</td>
                     <td>
                        <div id="imageContainter"> <img class="objectImg" src=''></div>
                     </td>
                     <td style="text-align: left;">Testing </td>
                     <td style="text-align: center;">3 </td>
                     <td style="text-align: center;">1050.00</td>
                     <td style="text-align: center;"></td>
                     <td style="text-align: center;word-wrap:break-word;">30%</td>
                     <td style="text-align: right;">2205.00</td>
                  <tr>          
                  <tr>
                     <td style="text-align: center;">1.</td>
                     <td style="text-align: left;">Testing</td>
                     <td>
                        <div id="imageContainter"> <img class="objectImg" src=''></div>
                     </td>
                     <td style="text-align: left;">Testing </td>
                     <td style="text-align: center;">3 </td>
                     <td style="text-align: center;">1050.00</td>
                     <td style="text-align: center;"></td>
                     <td style="text-align: center;word-wrap:break-word;">30%</td>
                     <td style="text-align: right;">2205.00</td>
                  <tr>          
                  <tr>
                     <td style="text-align: center;">1.</td>
                     <td style="text-align: left;">Testing</td>
                     <td>
                        <div id="imageContainter"> <img class="objectImg" src=''></div>
                     </td>
                     <td style="text-align: left;">Testing </td>
                     <td style="text-align: center;">3 </td>
                     <td style="text-align: center;">1050.00</td>
                     <td style="text-align: center;"></td>
                     <td style="text-align: center;word-wrap:break-word;">30%</td>
                     <td style="text-align: right;">2205.00</td>
                  <tr>          
                  <tr>
                     <td style="text-align: center;">1.</td>
                     <td style="text-align: left;">Testing</td>
                     <td>
                        <div id="imageContainter"> <img class="objectImg" src=''></div>
                     </td>
                     <td style="text-align: left;">Testing </td>
                     <td style="text-align: center;">3 </td>
                     <td style="text-align: center;">1050.00</td>
                     <td style="text-align: center;"></td>
                     <td style="text-align: center;word-wrap:break-word;">30%</td>
                     <td style="text-align: right;">2205.00</td>
                  <tr>          
                  <tr>
                     <td style="text-align: center;">1.</td>
                     <td style="text-align: left;">Testing</td>
                     <td>
                        <div id="imageContainter"> <img class="objectImg" src=''></div>
                     </td>
                     <td style="text-align: left;">Testing </td>
                     <td style="text-align: center;">3 </td>
                     <td style="text-align: center;">1050.00</td>
                     <td style="text-align: center;"></td>
                     <td style="text-align: center;word-wrap:break-word;">30%</td>
                     <td style="text-align: right;">2205.00</td>
                  <tr>          
                  <tr>
                     <td style="text-align: center;">1.</td>
                     <td style="text-align: left;">Testing</td>
                     <td>
                        <div id="imageContainter"> <img class="objectImg" src=''></div>
                     </td>
                     <td style="text-align: left;">Testing </td>
                     <td style="text-align: center;">3 </td>
                     <td style="text-align: center;">1050.00</td>
                     <td style="text-align: center;"></td>
                     <td style="text-align: center;word-wrap:break-word;">30%</td>
                     <td style="text-align: right;">2205.00</td>
                  <tr>        
                     </td>
                  </tr>
               </tbody>
            </table>
         </div>
   </body>
</html>

How to do calculation for two form fields in angular and patch it

[ReferenceImage][1]

->Hello, I need to do the calculation for two fields look at the reference image once.

->In the basic pay field if I enter 100 and in Gst % on the first premium amount if I enter 5 then automatically in the first premium amount 105 value should display calculation is like (100+5%100 = 105).

->same if I enter 5 in GST % on next premium amount 105 should be displayed in the next premium amount field.
[1]: https://i.stack.imgur.com/KNtAa.png

D3JsV3.5 – Single horizontal Stacked Bar Chart with Percentage

My goal is to create a horizontal stacked bar chart (1 bar) out of my data. The data looks like:

data = [{"Progress":20, "Value": 3}, {"Progress":80, "Value": 5}]

Where the X-Axis would be the Progress (its in %) from 0 to 100 in 10% steps. In the bar itself I would like then to give out the Value.enter image description here

This is my Code where im stuck at. I have big problems to stack my Data the way I need it. Any help is welcome.

function drawChartStackedBar(data){
  console.log(data);
  var margin = {
      top: 30,
      right: 20,
      bottom: 70,
      left: 50
    },
    width = 600 - margin.left - margin.right,
    height = 400 - margin.top - margin.bottom;
  // Adds the svg canvas
  var svg = d3.select("#barChartHistogramm")
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.top + margin.bottom)
    .append("g")
    .attr("transform",
      "translate(" + margin.left + "," + margin.top + ")");

  // Create x and y scale.
  var xScale = d3.scale.linear().range([0, width]);
  var yScale = d3.scale.ordinal().range([0, height]);

  // Create domains.
  xScale.domain([0, 100]);

  var xAxis = d3.svg.axis().scale(xScale)
    .orient("bottom").ticks(6);

    svg.append("g")
      .attr("class", "x axis")
      .attr("transform", "translate(0," + height + ")")
      .call(xAxis);
  // Create axes.
  var x_axis = svg.append('g')
    .attr('class', 'axis')
    .attr('padding', 1)
    .attr('transform', 'translate(' + 0 + ',' + height + ')')
    .call(d3.svg.axis(xScale)
      .ticks(1, 's'));

  // Choose which columns to have as keys with slice method.
  var keys = data.map(function(d) {
    return d.Progress;
  });


  var newData = [{}];
  data.forEach(function(d) {
    newData[0][d.Progress] = d.Value
  });

  var stack = d3.layout.stack();

  Create series of the data.
  var series = stack(newData);


  //Create color scale with colorbrewer or pass in array of colors.
  var colorScale = d3.scale.ordinal()
    .domain([0, 12])
    .range(d3.schemeCategory10);

  //Append rectangles.
  var bars = svg.selectAll(null)
    .data(data)
    .enter()
    .append('g')
    .attr('fill', function(d) {
      return colorScale(d.key);
    })
    .selectAll('rect')
    .data(function(d) {
      return d;
    })
    .enter()
    .append('rect')
    .attr('x', function(d, i) {
      return xScale(d[0]);
    })
    .attr('width', function(d, i) {
      return xScale(d[1]) - xScale(d[0]);
    })
    .attr("height", yScale.bandwidth());


    console.log('function ended');
}

Im using D3Js v3.5

Unable to get external css properties while trying to modify DOM . How can I solve the iss? [duplicate]

body{
    margin:0;
    justify-content: center;
    background: url(/image/bg-cover.png);
}
.des{
    padding-bottom:  100px; ;
}

.container{
    display: flex;
    overflow-x: auto;
    
}
.container ::-webkit-scrollbar{
    width:0px;
}

.wheelbg{
    height: 400px;
    width :600px;
    
    /* background-image: url(/image/wheel-bg.jpg); */
    margin-right: 33px;
    
    
    /* background: turquoise; */
    
}
.wheelbg img{
    height: 250px;
    width: auto;
    object-fit: cover;
    display: block;
    margin:auto;
    
}

button{
    padding: 10px;
    border: none;
    background: #37f;
    font-size: 30px;
    color: white;
    position: absolute;
    top:50%;
}
.nex{
    border-radius: 10px 0px 0px 10px;
    margin-left: 50em;


}
.prev{
    border-radius: 0px 10px 10px 0px;
}

button:hover{
    transform: scale(1.5);
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Varta:wght@300;400;500&display=swap">
</head>
<body>
    <h1>Wheels</h1>
    <p class="des">Lorem ipsum dolor sit amet consectetur adipisicing elit. Minus, dignissimos. Modi animi quam architecto, deleniti ipsum porro voluptatum dolorum fuga, ad et tempora laborum fugiat magnam, quidem aut reiciendis libero!</p>
    
   <button class="prev"><</button>
    
    <div class="container">
        <div class="wheelbg">
            <img src="image/1.png" alt="">
            wheel 1
        </div>
        <div class="wheelbg">
            <img src="image/2.png" alt="">
            wheel 2
        </div>
        <div class="wheelbg">
            <img src="image/3.png" alt="">
            Wheel 3
        </div>
        <div onclick="zoom()" class="wheelbg">
            <img src="image/4.png" alt="">
            <div>Wheel 4
                <p>
                    Lorem ipsum, dolor sit amet consectetur adipisicing elit. 

            </p></div> 
        </div>
    </div>
    <button class="nex">></button>
    <script  src="script.js"></script>
</body>
</html>

enter image description here

I am trying to make a webpage by following these rules:

  1. Convert the attached “layout.jpg” to HTML without using any html framework like (bootstrap, w3css etc.). The assets are shared in an image zip and use dummy content.
  2. Keep container maximum size of “1152px X 720px”. Layout should be vertical center position.
  3. Slider functionality should be enabled without using any plugin (as per design).
  4. Zoom functionality – by default all wheel images should be in normal state. On click, an active wheel should be zoomed smoothly as per design.
  5. While clicking left/right arrow, an active state will be inactive (zoom to normal state) and then move accordingly.
  6. If slide reached the beginning/end, the left/right side arrow should be disabled (unable to click)

While trying to do this, while fetching the css properties by document.getElementsByClassName(“wheelbg”).style.height;
it is showing height is not defined.
|i am using css external file.