How to while loop the div class in html [closed]

<div class="box">
    <div class="convv">
        <form action="" method="GET" class="hidden">
            <select data-conv-question="press one of them" name="category">
                <option value="button1">button1</option>
                <option value="button2">button2</option>
                <option value="button3">button3</option>
                <option value="button4">button4</option>
            </select>
        </form>
    </div>
</div>

My code is up there and my question is simple i just want to do this in a while loop. But i can fully understand the syntax of js for this problem.

Merge two or more trimmed Audio file into single wav file

We need to write a function that can merge two or more audio files and moreover, we are supposed to write a function for trimming the wat every part of the file we want to trim from the complete audio file from different tracks or different files of audio and merge into a single file. If two files have some overlap of time after it’s trimmed then it has to take both trimming parts also.

What is the most intelligent way to close the Dropdown Menu on clicking outside of its scope?

I have created this simple Dropdown in React and everything works fine until I click outside the scope of the Dropdown.
https://codesandbox.io/s/restless-fast-x2jhe8

I’ve added a min-height: 100vh property on the body, to replicate a full size page. Like I said, the functionality to close the Dropdown menu when we click anywhere in the page that is not the Dropdown, is not implemented yet. I am not sure how to handle this in the most elegant way. I tried something along the lines of adding an event listener on the body with useEffect and then checking if event.target has class dropdown, but it didn’t perform as expected.

Passing function result into a JSON file

So i was given task to build similarity-checker based on react.js
then i was puzzled to display the result , can anyone help me 🙂 .
any help will be great.
this my code :

App.js

import './App.css';
import DisplayData from './display';
import React from 'react';
let input = React.createRef() ;
function handleSubmit(){
  var x =(input.current.value);
  input.toString();
  var stringSimilarity = require("string-similarity")
  let mapel = require('./data-mapel.json')
  const a = (JSON.stringify(mapel[0]))
  var Similarity1= stringSimilarity.compareTwoStrings(x,a)*100
  const result1=Similarity1
  const b = (JSON.stringify(mapel[1]))
  var Similarity2= stringSimilarity.compareTwoStrings(x,b)*100
  const result2=Similarity2
  const c = (JSON.stringify(mapel[2]))
  var Similarity3= stringSimilarity.compareTwoStrings(x,c)*100
  const result3=Similarity3
  const d = (JSON.stringify(mapel[3]))
  var Similarity4= stringSimilarity.compareTwoStrings(x,d)*100
  const result4=Similarity4
  const e = (JSON.stringify(mapel[4]))
  var Similarity5= stringSimilarity.compareTwoStrings(x,e)*100
  const result5=Similarity5
  const f = (JSON.stringify(mapel[5]))
  var Similarity6= stringSimilarity.compareTwoStrings(x,f)*100
  const result6=Similarity6
  const g = (JSON.stringify(mapel[6]))
  var Similarity7= stringSimilarity.compareTwoStrings(x,g)*100
  const result7=Similarity7
  const h = (JSON.stringify(mapel[7]))
  var Similarity8= stringSimilarity.compareTwoStrings(x,h)*100
  const result8=Similarity8
  const i = (JSON.stringify(mapel[8]))
  var Similarity9= stringSimilarity.compareTwoStrings(x,i)*100
  const result9=Similarity9
  const all = [result1,result2,result3,result4]
}
function App() {
return (
  <div className="App">
    <div className="container">
    <h1 className="px-2 py-2">Similarity Checker</h1>
    <form>
    <div className="form-group">
          <label htmlFor=""></label>
          <input type="text" className="form-control" name="input" placeholder="Masukkan Kata" ref={input} />    
          &nbsp;&nbsp;
          <button type="submit" className="buttona" onClick={handleSubmit}>Enter</button>
        </div>
    </form>
    <br></br>
      <center>
      <DisplayData/>
      </center>
    </div>
    </div>
);

}
export default App;

DisplayData.js

import React from "react";
import Mapel from './data-mapel.json'
import "react-table";
function DisplayData() {
    const DisplayMapel=Mapel.map(
    (data)=>{
        return(
            <tr>
                <td>
                    {data["mapela"]}
                    {data["mapelb"]}
                    {data["mapelc"]}
                    {data["mapeld"]}
                    {data["mapele"]}
                    {data["mapelf"]}
                    {data["mapelg"]}
                    {data["mapelh"]}
                    {data["mapeli"]}
                </td>
                <td>
                    =
                </td>
                <td>
                    {data["resulta"]}
                    {data["resultb"]}
                    {data["resultc"]}
                    {data["resultd"]}
                    {data["resulte"]}
                    {data["resultf"]}
                    {data["resultg"]}
                    {data["resulth"]}
                    {data["resulti"]}
                </td>

            </tr>
        )
    }
    )


  return(
      <div>
          <table className="table table-striped border-2">
          <thead>
              <tr>
                  <th>Mata Pelajaran</th>
              </tr>
              <tr></tr>
              </thead>    
        <tbody>
            {DisplayMapel}
        </tbody>
        </table>
      </div>
  )
}


export default DisplayData;

data-mapel.json

[
    {
        "mapela":"Bahasa Indonesia",
        "resulta":"0%"
    },
    {
        "mapelb":"Ilmu Pengetahuan Alam",
        "resultb":"0%"
    },
    {
        "mapelc":"Bahasa Arab",
        "resultc":"0%"
    },
    {
        "mapeld":"Ilmu Pengetahuan Sosial",
        "resultd":"0%"
    },
    {
        "mapele":"Bahasa Inggris",
        "resulte":"0%"
    },
    {
        "mapelf":"Kimia",
        "resultf":"0%"
    },
    {
        "mapelg":"Biologi",
        "resultg":"0%"
    },
    {
        "mapelh":"Seni Budaya",
        "resulth":"0%"
    },
    {
        "mapeli":"Prakarya",
        "resulti":"0%"
    }
]

sorry if this question very messy,this was my first question 🙂
thank you for your answer !

i’ve been trying to place the function result into json data . but that thing just puzzling me back 🙂

Audio Files Stored in S3 are not Playable

I can successfully upload audiofiles to AWS S3, however the files do not play whether downloaded or played in the browser. The files do have a filesize.

I’m uploading an audioBlob object to AWS S3:

const [audioBlob, setAudioBlob] = useState(null)


const submitVoiceMemo = async () => {
    try {
      await fetch('/api/createVoiceMemo', {
        method: 'PUT',
        body: audioBlob
      })
    } catch (error) {
      console.error(error)
    }
  }

This is the API Route:

module.exports = requireAuth(async (req, res) => {
  try {
    AWS.config.update({
      accessKeyId: process.env.AWS_ACCESS_KEY_1,
      secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY_ID,
      region: 'us-east-2',
      signatureVersion: 'v4'
    })

    const s3 = new AWS.S3();

    const uuid = randomUUID()
    const s3Params = {
      Bucket: 'waveforms',
      Key: `voicememo/${uuid}.mp3`,
      Body: req.body,
      ContentType: 'audio/mpeg',
      ACL: 'public-read'
    }

    await s3.upload(s3Params).promise()

  } catch (e) {
    res.status(500).json({ error: e.message })
  }
})

As per this question, I have confirmed that req.body is a string.

The file being received by S3 has a filesize and the correct contentType when checked in the S3 console. It just isn’t playable when downloaded or played directly in the browser.


Below is how audioBlob and also audioFile (an MP3) are generated (Basically the user records a voice memo and when they click stopRecording, raw audio is stored as state):

const stopRecording = () => {
    recorder.current
      .stop()
      .getMp3()
      .then(([buffer, blob]) => {
        const file = new File(buffer, 'audio.mp3', {
          type: blob.type,
          lastModified: Date.now()
        })
        setAudioBlob(blob)
        const newBlobUrl = URL.createObjectURL(blob)
        setBlobUrl(newBlobUrl)
        setIsRecording(false)
        setAudioFile(file)
      })
      .catch(e => console.log(e))
  }

How can I correctly store audio generated on the front-end, in S3?

How can I convert JSON returned from AWS command line by javascript and get lastRun in Cucumber

I have declaration step by javascript like this

When('get schedule and state from {string} of batch {string}', function (awsProfile, batchName) {
  batchName = getVal(batchName, this)
  awsProfile = getVal(awsProfile, this)
  const args = ['events', 'describe-rule', '--profile', awsProfile, '--name', batchName]
  const res = runAWS(args)
  return res
})

The res is return result like this

......{ 
stdout: '{rn' + 
' "Name": "time",rn' + 
' "ScheduleExpression": "12:00",rn' + 
' "State": "VN",rn' '}rn' 
status: 0 
}

and then I just like to make like a json not have include “nr” or “‘”. I put more step is

When('get schedule and state from {string} of batch {string}', function (awsProfile, batchName) {
      batchName = getVal(batchName, this)
      awsProfile = getVal(awsProfile, this)
      const args = ['events', 'describe-rule', '--profile', awsProfile, '--name', batchName]
      const res = runAWS(args)
      const getJson = JSON.parse(res.stdout) //NEW LINE
      return res
    })

And the result is

  ......
   {
      Name: 'time',
      ScheduleExpression: '12:00',
      State: 'VN'
   }
  ...

It’s not like a json what I need, as I need is:

       {
          "Name": "time",
          "ScheduleExpression": "12:00",
          "State": "VN"
       }
      

How can I make change like that, and set assign a name for that json like this:

info {
       "Name": "time",
       "ScheduleExpression": "12:00",
       "State": "VN"
}

Please help me, I need to get this result and save it in a file.
this function I make in a nother file, and called by Cucumber.

Thank you so much

How to remove dot dot in javascript and get data from that by Cucumber

When I run a commandline from AWS to get name and state it’s through for me like this:

const res = runAWS(args) (note: args is the place I verify line of AWS to run)

and the result is

......{
  stdout: '{rn' +
    '    "Name": "time",rn' +
    '    "ScheduleExpression": "12:00",rn' +
    '    "State": "VN",rn'
    '}rn',
  status: 0
}

Then I use JSON.parse(res.stdout) to look like more clear like this

 ......
    {
      Name: 'time',
      ScheduleExpression: '12:00',
      State: 'VN'
    }
    ...

But now when I get lastRun in cucumber, it’s through nothing for me,
also it show that: lastRun is not defind.
How can I get data from that json in cucumber please, that step is I write by myself. but now I dont know how to get lastRun like CUCUmber to save that data in a file.

please help me, thank you

can someone please explain how the following code changes the value of “xs”? it should remain the same

function allDifferent(xs){
   for(x of xs){

        let array1 = xs;
        let index = xs.indexOf(x);
        array1.splice(index, 1);

        if(array1.includes(x)){
           return false;
        }

   }
   return true;
}

I am trying to check if every element of the array “xs” is different by removing every element one by one and then checking if the remaining array still includes the value of that element somewhere else.

btw I already solved the problem in a different way so that i don’t need splice but i would just like to understand.

Why Javascript is throwing an error on the selected index value [closed]

I have the code where i am doing select from one and on the basis of that, it will load a second select, but i am getting errors, once such error is:

if (document.forms[0].TwoSelectsRelated1.options[menuNum].value == '') return;

Error is:

Uncaught TypeError: Cannot read properties of undefined (reading 'options')

and this is my complete javascript, i am doing a 3 related selects here

How to get checkbox value using React

I ve got a form consisits of two inputs (emain, password) and one checkbox. Code is here:

<Box component="form" onSubmit={handleSubmit} noValidate sx={{ mt: 1 }}>
  <TextField
    margin="normal"
    required
    fullWidth
    id="email"
    label="Email adress"
    name="email"
    autoComplete="email"
    autoFocus
  />
  <TextField
    margin="normal"
    required
    fullWidth
    name="password"
    label="Password"
    type="password"
    id="password"
    autoComplete="current-password"
  />
  <FormControlLabel
    control={<Checkbox value="remember" color="primary" />}
    label="Remember me"
  />
  <Button
    type="submit"
    fullWidth
    variant="contained"
    sx={{ mt: 3, mb: 2 }}
  >
    Sign in
  </Button>
</Box>

To get the values of Email and Password I use smth.like:

  const handleSubmit = (event) => {
    event.preventDefault();
    const data = new FormData(event.currentTarget);
    console.log({
      email: data.get('email'),
      password: data.get('password'),
    });
  };

But what’s the best practice to get the value of checkbox “Remember me” (in FormControlLabel)? Of course, I can make a new function to handle the changes of checkbox like:

<FormControlLabel
 control={<Checkbox value="remember" color="primary" />}
 onChanges = {newFunction}
 label="Remember me"
/>

But I think that’s it’s not a good idea, because I don’t need to get all the changes of this checkbox, I just need to know the value of this checkbox in the moment of submitting the form.

Regular expression is overwriting css styles in html

I used regular expressions to make everything bold before the colon. But it is overwriting my css styles.

I want that the css styles are displayed. But don’t know how to fix this. I have tried to use !important next to the hex. But that didn’t work. Do I need to change the regular expression. Or do I need a new line of code?

<ul>
 <li>Apple: Has the color <span style="background-color:#FF0000">red</span></li>
 <li>Orange: Has the color <span style="background-color:#FFAE00">orange</span></li>
 <li>Banana: Has the color yellow</li>
 <li>Blackberries: Has the color purple</li>
 <li>Avocado: Has the color green</li>
</ul>

 <script type="text/javascript">

   let list = document.querySelectorAll("ul li");
   list.forEach((element) => {
     element.innerHTML = element.innerText.replace(/^[^:]+:/, '<b>$&</b>');
     
 </script>

How to get all multiple keys pressed in javascript?

i found this jsfiddle, that should show all keys pressed on the keyboard. The code looks fine, but it does not seem to work, at least on my keyboard: https://jsfiddle.net/HwR9N/3/

When i press all the arrow keys, only two of the keys get listed.

I work with a similar code, to create a javascript game, but i got the same problem there:

//List of all keys pressed or up
    var keymap = [];
    window.addEventListener("keydown",
        function(e){
            keymap[e.keyCode] = true;
            checkCombinations(e);
        },
    false);
    
    window.addEventListener('keyup',
        function(e){
            keymap[e.keyCode] = false;
        },
    false);

A strange thing is, that the WASD keys work all at the same time.
Does anybody know a different method, that works on every keyboard? I haven’t tried another keyboard yet. Im working on a HP Laptop. OS is Windows 10. Problem occurs in Chrome and Firefox.

Im thankfull for any advice.

Greets,
Florian

How do I make Vite build my files every time a change is made?

I’m trying to make Vite build my files and output them into the dist folder every time I save/make changes on to my files during development.

How would I do that?

Here is my vite.config.development.js file:

import { defineConfig } from "vite";
export default defineConfig({
    base: "./",
    build: {
        rollupOptions: {
            output: {
                assetFileNames: "assets/[name].[ext]",
                chunkFileNames: "assets/[name].[ext]",
                entryFileNames: "assets/[name].js",
            },
        },
        write: true,
    },
});

Here is my scripts in packagae.json:

"frontend-dev": "vite --config vite.config.development.js",

It does the usual localhost:3000 thing, but it does not build my files and put them in the dist folder when I make changes to my source code.

Currently, I have to run a vite build npm script every time which takes a lot of time.

Why is the 500px padding for the div not working?

<!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">
</head>

<body>
    <nav>
        <navl>
            <ul> 
                <li><img src="home.png" alt="logo"></li>
                <li class="src"><input type="search"></li>
                <li><img src="search.png" alt="hit"></li>
            </ul>
        </navl>

        <navr>
            <ul>
                <li><img src="party.png" alt="dp" style="width: 30px;" ></li>
                <li style="font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif; color:white;padding-top: 6px;">Jason</li>
                <li>i1</li>
                <li>i2</li>
                <li>i3</li>
                <li>i4</li>
                <li>i5</li>
            </ul>
        </navr>
    </nav>
    <main>
        <left>
            <span>left</span>
        </left>
        <content>
            <cover>

            </cover>
            <interact>
                <l-int>

                </l-int>
                <r-int>

                </r-int>
            </interact>
            <feed>
                <center>
                    <post>
                        <headd>
                            <img s id="pp" src="dp.jpg"" srcset="">
                            <det>
                            <a style="text-decoration: none;" href=""> Jason </a>
                                <t sxtyle="border: 2px blue groove;">
                            <span style="font-size: small;"><br>1 yr </span>
                         <img src="globe.png" alt="" width="17px" height="17px" >      
                        </t>
                        </det>
                        
                        </headd>
                        <span>The best part of the day ! The logo of the free online
                             encyclopedia Wikipedia is an unfinished globe constructed
                             from jigsaw pieces—some pieces are missing 
                             at the top—each inscribed with a glyph from a different writing system <br> </span>

                             <img id="pp2" src="postt22.jpg" alt="">
                    </post>
                </center>
                <right>
                    <span>right</span>
                </right>
            </feed>
        </content>
    </main>


</body>

</html>
*{
    padding: 0vw;
    margin: 0vw;
}

nav{
    background-color: rgba(52, 52, 146, 0.829);
    display: inline-flex;
    justify-content: space-around;
    align-items: center;
    width: 100%;
    height: 45px;
    position:sticky;
    top: 0px;
}

ul {
    display: inline-flex;
    list-style-type:none;

}

navl{
    border-color:red ;
    border-style: dotted;
    align-items: center;}
navr{
    border-color:red ;
    border-style: dotted;

}

main{
    justify-content: space-between;
    display: flex;
}
left{
    border-color: red;
    border-style: dotted;
    width: 30vw;
    height: 400px;
    display: inline-flex;
    position: sticky;
    top: 45px;
}
center{
    border-color: red;
    border-style: dotted;
    width: 30vw;
    height:5000px;
    display: inline-flex;
    overflow: hidden;
}
right{
    border-color: red;
    border-style: dotted;
    width: 27vw;
    height: 300px;
    display: inline-flex;
}

cover{
    border-style: dashed;
    border-color: red;
    width: 60vw;
    height: 350px;
    background-image: url(cover.jpg);
}

content{
    display:flex;
    flex-direction: column;
}

main{
    padding: 0px 60px;
    border:10px greenyellow double ;
}

interact{
    width: 60vw;
    height: 30px;
    border: 5px blue dashed;
}

feed{
    margin-top: 20px;
}

.src{
    
}

body{
    background-color: rgba(33, 59, 82, 0.473);
}
}

#pp{
    width: 30px;
    height: 30px;
}

headd{
    padding: 10px;
    border: 2px rgb(106, 17, 207) groove;
    display: flex;
    flex-direction:row;
    width: 28vw;   
    height: 30px; 
    margin-bottom: 20px;
}

post{
    background-color: azure;
    margin: 1px;
    padding: 2px 500px 2px 2px;
    text-align: left;
}
#pp2{
    width:100px
    height:100px;
    margin-top:  20px;
}

Why is the 500px padding for the div not working? Only the code within the div would be needed for this question. I am a beginner trying to learn web development using HTML,C CSS AND JAVASCRIPT. I am trying to make a facebook clone. Any help would be appreciated regarding
this problem……….. Thank you