Please why is my code not working,do I need to install any library

Recently started functional programming and all explanations of the pipe and compose using reduce which I have seen are very sketchy.

Const x = 4

Const add2 = x+2

Const multiplyBy5 = x*5

Const subtract1 = x-1

pipe=(…functions)=>
(x)=>functions.reduce((v,function)=>function(v),x)
const
result=pipe(add2,multiplyBy5,subtract1)(4)
console.log(result)

Ask the user before submitting the form

I have a cshtml page with this code:

<form action='@Url.Action("ExportExcel", "Records")' method="post" target="_blank" onsubmit="return exportExcel(), true">
            <input type="hidden" name="filteredRecordsIds" id="filteredRecordsIds" value="" />
            <input id="btnExportExcel" type="submit" hidden="hidden" />
        </form>

in js the exportExcel function:

function exportExcel() {
 $('#filteredRecordsIds').val(filteredRecords.map(function (record) { return record.Id }));
    return true;
}

in controller Records:

public ActionResult ExportExcel(string filteredRecordsIds)
        {...}

I would like to add modal/popup, before the submitting that ask the user:

“Would you like to export with calculations?” with 2 buttons options: “Yes” or “No”.

Depending on the user’s response, I would like to send the answer to the controller (as second parameter).

How can I add that?

Thank You!

How do I use an array from main js file for different js file?

I have a task to make a blog thumbnail and blog content from input that looks like this: blog.html

This is the thumbnails which is located in the same HTML file as the input form: blog.html

This is the blog content and what I’m trying to achieve which is located in the different HTML file: blog-detail.html

I have 2 js files, blog.js for blog.html and blog-detail.js for blog-detail.html. All of the blog value is saved in let blogs = [] in blog.js

This is the snippet from the blog input and thumbnails:

let blogs = []



let month = [
    "Jan",
    "Feb",
    "Mar",
    "Apr",
    "May",
    "Jun",
    "Jul",
    "Aug",
    "Sept",
    "Oct",
    "Nov",
    "Dec"
]

function addBlog(event) {
    event.preventDefault()

    let inputName = document.getElementById("inputProjectName").value
    let inputContent = document.getElementById("inputDescription").value
    let inputImage = document.getElementById("inputImage").files[0]

    const projectDate = {

        startDate: document.getElementById("inputStartDate").value,
        endDate: document.getElementById("inputEndDate").value
    }

    inputImage = URL.createObjectURL(inputImage)

    let cardIcons = {
        html: document.querySelector('input[name="checkHtml"]').checked,
        css: document.querySelector('input[name="checkCss"]').checked,
        nodeJs: document.querySelector('input[name="checkNode"]').checked,
        reactJs: document.querySelector('input[name="checkReact"]').checked
    }

    let blog = {
        title: inputName,
        date: projectDate,
        content: inputContent,
        icons: cardIcons,
        image: inputImage
    }

    blogs.push(blog)

    console.table(blogs)

    renderCard()
}

function renderCard() {

    let containerBlog = document.getElementById("contents")
    containerBlog.innerHTML = '';

    for (let i = 0; i < blogs.length; i++) {

        containerBlog.innerHTML += `
        <div id="contents" class="mp-card">
            <!--MPC = My Project Card-->
            <div class="mpc-img">
                <img src="${blogs[i].image}" alt="">
            </div>
            <div class="mpc-title">
            <a href="blog-detail.html">
                <p>${blogs[i].title}</p>
            </a>
            </div>
            <div class="mpc-duration">
                <small>Durasi: 1 Bulan</small>
            </div>
            <div class="mpc-content">
                ${blogs[i].content}
            </div>
            <div class="mpc-icons">
                ${(blogs[i].icons.html === true) ? '<i class="fa-brands fa-html5"></i>' : ''}
                ${(blogs[i].icons.css === true) ? '<i class="fa-brands fa-css3-alt"></i>' : ''}
                ${(blogs[i].icons.nodeJs === true) ? '<i class="fa-brands fa-node-js"></i>' : ''}
                ${(blogs[i].icons.reactJs === true) ? '<i class="fa-brands fa-react"></i>' : ''}  
            </div>
            <div class="mpc-mod">
                <button>Edit</button>
                <button>Delete</button>
            </div>
        </div>
        `
    }
}
/* My Project */


/* FORM */

.mpi-title {
    width: 100%;
    margin: 50px 0px;
    font-size: 30px;
    text-align: center;
    font-family: 'Lato', sans-serif !important;
    font-weight: 700;
}

.mpi-form-container {
    display: flex;
    justify-content: center;
}

.mpi-form {
    width: 540px;
    display: flex;
    justify-content: center;
}

.mpi-form label {
    font-size: 25px;
    font-weight: bold;
}

.mpi-form .mpi-name input,
.mpi-date input {
    width: 100%;
    height: 50px;
    padding: 5px;
    box-sizing: border-box;
    font-size: 20px;
    font-weight: 400;
    padding-bottom: 5px;
    margin-top: 5px;
    margin-bottom: 20px;
    border: 1px solid #c4c4c4;
    border-radius: 8px;
    box-shadow: 0 5px 5px rgb(0 0 0 / 26%);
}

.mpi-date {
    flex-grow: 1;
    display: flex;
    gap: 10px;
}

.mpi-date .date-start {
    flex: 50%;
}

.mpi-date .date-end {
    flex: 50%;
}

[type="date"]::-webkit-datetime-edit {
    opacity: 0;
}

[type="date"]::-webkit-calendar-picker-indicator {
    opacity: 0;
    width: 100%;
}

.mpi-desc textarea {
    width: 100%;
    font-size: 20px;
    font-weight: 400;
    padding: 8px;
    margin-top: 5px;
    margin-bottom: 20px;
    border: 1px solid #c4c4c4;
    box-sizing: border-box;
    border-radius: 8px;
    height: 200px;
}

.mpi-check {
    display: flex;
    gap: 120px;
    margin: 20px 0px;
}

.mpi-check label {
    font-size: 20px;
}

.check-left {
    display: flex;
    flex-direction: column;
    row-gap: 20px;
}

.check-right {
    display: flex;
    flex-direction: column;
    row-gap: 20px;
}

.check-label {
    display: block;
    position: relative;
    padding-left: 35px;
    color: #514a4a;
    margin-bottom: 12px;
    cursor: pointer;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.check-label input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.checkmark {
    position: absolute;
    top: 0;
    left: 0;
    height: 25px;
    width: 25px;
    background-color: white;
    border-radius: 5px;
    box-shadow: 0 5px 5px rgb(0 0 0 / 26%);
}

.check-label:hover input~.checkmark {
    background-color: #ccc;
}

.check-label input:checked~.checkmark {
    background-color: #2196F3;
}

.checkmark:after {
    content: "";
    position: absolute;
    display: none;
}

.check-label input:checked~.checkmark:after {
    display: block;
}

.check-label .checkmark:after {
    left: 9px;
    top: 5px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 3px 3px 0;
    -webkit-transform: rotate(45deg);
    -ms-transform: rotate(45deg);
    transform: rotate(45deg);
}

.mpi-image {
    overflow: hidden;
    height: 50px;
    width: 100%;
    font-size: 20px;
    font-weight: 400;
    box-sizing: border-box;
    margin-top: 5px;
    margin-bottom: 20px;
    background: #f4f3f3;
    border: 1px solid #c4c4c4;
    border-radius: 8px;
    cursor: pointer;
    padding-right: 8px;
    box-shadow: 0 10px 10px rgb(0 0 0 / 26%);
}

.mpi-image label {
    width: 100%;
    height: 50px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.mpi-choose {
    margin-top: -2px;
    border-radius: 8px;
    align-items: center;
    padding: 13px 10px 13px 10px;
    background-color: #e4e4e4;
    color: #b2abab;
}

.mpi-attach {
    padding-right: 10px;
}

.mpi-submit button {
    margin-top: 30px;
    float: right;
    padding: 10px 30px;
    border: none;
    border-radius: 25px;
    background-color: var(--btn);
    color: white;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
    margin-bottom: 110px;
}

.mpi-submit button:hover {
    background-color: var(--btn-hover)
}


/* x FORM */


/* CARDS */

.mp-container {
    width: 100%;
    background-color: #f8f8f8;
    padding-bottom: 70px;
}

.mp-card-container {
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;
    gap: 20px 140px;
    padding: 0px 70px 0px 70px;
}

.mp-title {
    width: 100%;
    display: flex;
    font-size: 30px;
    font-weight: bold;
    justify-content: center;
    padding: 40px 0px;
}

.mp-card {
    width: 320px;
    height: 440px;
    max-width: 280px;
    max-height: 440px;
    padding: 10px 15px 10px 15px;
    border: none;
    border-radius: 10px;
    background-color: white;
    box-shadow: rgba(149, 157, 165, 0.2) 0px 8px 24px;
}

.mpc-img img {
    border-radius: 10px;
    width: 100%;
    height: 200px;
    object-fit: cover;
}

.mpc-title {
    overflow: hidden;
    margin-top: 10px;
    font-weight: 900;
}

.mpc-title a {
    text-decoration: none;
    color: black;
}

.mpc-title a:hover {
    text-decoration: underline
}

.mpc-content {
    height: 60px;
    overflow: hidden;
    margin: 20px 0px 20px 0px;
    text-align: justify;
    word-wrap: break-word;
    text-align: justify;
}

.mpc-icons {
    display: flex;
    font-size: 32px;
    gap: 15px;
}

.mpc-mod {
    display: flex;
    gap: 10px;
    text-align: center;
    margin-top: 20px;
}

.mpc-mod button {
    padding: 5px 10px;
    border: 0;
    border-radius: 4px;
    background: var(--btn);
    color: #fff;
    cursor: pointer;
    width: 50%;
}

.mpc-mod button:hover {
    background-color: var(--btn-hover)
}


/* x CARDS x */


/* x My Project x */
<!--MPI = My Project Input-->
    <div class="mpi-title">
        <p>ADD BLOG</p>
    </div>
    <!--Form-->
    <div class="mpi-form-container">
        <div class="mpi-form">
            <!--MP = My Project Input-->
            <form onsubmit="addBlog(event)">
                <div class="mpi-name">
                    <label for="inputProjectName">Project Name</label>
                    <input type="text" id="inputProjectName">
                </div>
                <div class="mpi-date">
                    <div class="date-start">
                        <label for="inputStartDate">Start Date</label>
                        <input type="date" id="inputStartDate">
                    </div>
                    <div class="date-end">
                        <label for="inputEndDate">End Date</label>
                        <input type="date" id="inputEndDate">
                    </div>
                </div>
                <div class="mpi-desc">
                    <label for="inputDescription">Description</label>
                    <textarea name="inputDescription" id="inputDescription"></textarea>
                </div>
                <div class="mpi-check-cont">
                    <label for="checkTitle">Technologies</label>
                    <div class="mpi-check">
                        <div class="check-left">
                            <div>
                                <label for="checkHtml" class="check-label">HTML
                                    <input type="checkbox" id="checkHtml" name="checkHtml"check>
                                    <span class="checkmark"></span>
                                </label>
                            </div>
                            <div>
                                <label for="checkNode" class="check-label">Node Js
                                    <input type="checkbox" id="checkNode" name="checkNode">
                                    <span class="checkmark"></span>
                                </label>
                            </div>
                        </div>
                        <div class="check-right">
                            <div>
                                <label for="checkCss" class="check-label">CSS
                                    <input type="checkbox" id="checkCss" name="checkCss">
                                    <span class="checkmark"></span>
                                </label>
                            </div>
                            <div>
                                <label for="checkReact" class="check-label">React Js
                                    <input type="checkbox" id="checkReact" name="checkReact">
                                    <span class="checkmark"></span>
                                </label>
                            </div>
                        </div>
                    </div>
                </div>
                <div>
                    <label>Upload Image</label>
                    <div class="mpi-image">
                        <label for="inputImage">
                    <div class="mpi-choose">Choose</div>
                    <div class="mpi-attach"><i class="fa-solid fa-paperclip"></i></div>
                    </label>
                        <input type="file" id="inputImage" hidden />
                    </div>
                </div>
                <div class="mpi-submit">
                    <button type="submit">Submit</button>
                </div>
            </form>
        </div>
    </div>
    <!--xFormx-->

<div class="mp-container">
        <div class="mp-title">
            <p>MY PROJECT</p>
        </div>
        <div id="contents" class="mp-card-container">
            <div class="mp-card">
                <!--MPC = My Project Card-->
                <div class="mpc-img">
                    <img src="assets/phone1.jpg" alt="">
                </div>
                <div class="mpc-title">
                    <a href="blog-detail.html">
                        <p>Dumbways Mobile App - 2022</p>
                    </a>
                </div>
                <div class="mpc-duration">
                    <small>Duration: 2 Month</small>
                </div>
                <div class="mpc-content">
                    Lorem ipsum dolor sit amet consectetur adipisicing elit. Doloremque temporibus excepturi deserunt consequuntur molestias adipisci corporis neque error. Delectus, dolorum dolorem neque vel earum ipsam ut fugiat quos distinctio blanditiis.
                </div>
                <div class="mpc-icons">
                    <i class="fa-brands fa-html5"></i>
                    <i class="fa-brands fa-css3-alt"></i>
                    <i class="fa-brands fa-node-js"></i>
                    <i class="fa-brands fa-react"></i>
                </div>
                <div class="mpc-mod">
                    <button>Edit</button>
                    <button>Delete</button>
                </div>
            </div>
        </div>

    </div>

This is the snippet from the blog detail:

document.getElementById("blog-detail").innerHTML = `
    <div class="bd-title">
        <p>${blogs[i].title}</p>
    </div>
    <div class="bd-idc">
    <div class="idc-left">
        <img src="${blogs[i].image}" alt="Blog Image">
    </div>
    <div class="idc-right">
        <p>Duration</p>
        <div class="bd-duration">
            <div style="padding-left: 2px;">
                <i class="fa-solid fa-calendar-days"></i>
                <p>1 Jan 2021 - 1 Feb 2021</p>
            </div>
            <div>
                <i class="fa-solid fa-clock"></i>
                <p>1 Month</p>
            </div>
        </div>
        <div class="bd-tech">
            <p>Technologies</p>
            <div class="i-tech">
                <!--TI = Tech Icon-->
                <div class="ti-left">
                    <div>
                    ${(blogs[i].icons.html === true) ? '<i class="fa-brands fa-html5"></i>' : ''}
                        <p>HTML</p>
                    </div>
                    <div>
                    ${(blogs[i].icons.nodeJs === true) ? '<i class="fa-brands fa-node-js"></i>' : ''}
                        <p>nodeJs </p>
                    </div>
                </div>
                <div class="ti-right">
                    <div>
                    ${(blogs[i].icons.css === true) ? '<i class="fa-brands fa-css3-alt"></i>' : ''}
                        <p>CSS</p>
                    </div>
                    <div>
                    ${(blogs[i].icons.reactJs === true) ? '<i class="fa-brands fa-react"></i>' : ''}
                        <p>ReactJs</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="bd-content">
    <p>
        ${blogs[i].content}
    </p>
</div>
    `;
/* Blog Detail */

.bd-title {
    margin: 50px 0px;
    text-align: center;
    font-size: 40px;
    font-weight: bold;
}

.bd-idc {
    width: 100%;
    display: flex;
    padding: 0px 50px;
    gap: 20px;
}

.idc-left {
    flex: 55%;
    overflow: hidden;
    object-fit: cover;
    padding: 0px 20px
}

.idc-left img {
    width: 100%;
    height: 400px;
    object-fit: cover;
}

.idc-right {
    flex: 45%
}

.idc-right p {
    font-size: 30px;
    font-weight: bold;
}

.bd-duration {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.bd-duration p {
    font-size: 30px;
    font-weight: bold;
}

.bd-duration div {
    display: flex;
    align-items: center;
    gap: 10px;
}

.bd-duration div p {
    font-size: 20px;
}

.bd-duration div i {
    font-size: 30px;
}

.bd-tech {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.bd-tech p {
    font-size: 30px;
    font-weight: bold;
}

.i-tech {
    display: flex;
    gap: 0px 60px;
}

.ti-left div {
    display: flex;
    gap: 0px 20px;
    margin-bottom: 20px;
}

.ti-right div {
    display: flex;
    gap: 0px 20px;
    margin-bottom: 20px;
}

.bd-tech div p {
    font-size: 20px;
}

.bd-tech div i {
    font-size: 30px;
}

.bd-content {
    margin-top: 50px;
    padding: 0px 68px;
}

.bd-content p {
    font-size: 20px;
    text-align: justify;
}


/* x Blog Detail x */
<!--Blog Detail-->
    <div id="blog-detail">
        <!--BD = Blog Detail-->
        <div class="bd-title">
            <p>Blog Title</p>
        </div>
        <!--IDC = Image, Duration, Categories-->
        <div class="bd-idc">
            <div class="idc-left">
                <img src="assets/phone5.jpg" alt="Blog Image">
            </div>
            <div class="idc-right">
                <p>Duration</p>
                <div class="bd-duration">
                    <div style="padding-left: 2px;">
                        <i class="fa-solid fa-calendar-days"></i>
                        <p>1 Jan 2022 - 1 Aug 2022</p>
                    </div>
                    <div>
                        <i class="fa-solid fa-clock"></i>
                        <p>8 Month</p>
                    </div>
                </div>
                <div class="bd-tech">
                    <p>Technologies</p>
                    <div class="i-tech">
                        <!--TI = Tech Icon-->
                        <div class="ti-left">
                            <div>
                                <i class="fa-brands fa-html5"></i>
                                <p>HTML</p>
                            </div>
                            <div>
                                <i class="fa-brands fa-node-js"></i>
                                <p>nodeJs </p>
                            </div>
                        </div>
                        <div class="ti-right">
                            <div>
                                <i class="fa-brands fa-css3-alt"></i>
                                <p>CSS</p>
                            </div>
                            <div>
                                <i class="fa-brands fa-react"></i>
                                <p>ReactJs</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="bd-content">
            <p>
                Lorem ipsum dolor sit amet consectetur adipisicing elit. Suscipit libero sapiente, minus atque a nesciunt ipsum? Illum sapiente odio provident maxime aut nihil voluptatem officia voluptatibus vel! Necessitatibus, ipsam esse. Lorem ipsum dolor sit amet
                consectetur adipisicing elit. Suscipit libero sapiente, minus atque a nesciunt ipsum? Illum sapiente odio provident maxime aut nihil voluptatem officia voluptatibus vel! Necessitatibus, ipsam esse. Lorem ipsum dolor sit amet consectetur
                adipisicing elit. Suscipit libero sapiente, minus atque a nesciunt ipsum? Illum sapiente odio provident maxime aut nihil voluptatem officia voluptatibus vel! Necessitatibus, ipsam esse. Lorem ipsum dolor sit amet consectetur adipisicing
                elit. Suscipit libero sapiente, minus atque a nesciunt ipsum? Illum sapiente odio provident maxime aut nihil voluptatem officia voluptatibus vel! Necessitatibus, ipsam esse. Lorem ipsum dolor sit amet consectetur adipisicing elit. Suscipit
                libero sapiente, minus atque a nesciunt ipsum? Illum sapiente odio provident maxime aut nihil voluptatem officia voluptatibus vel! Necessitatibus, ipsam esse. Lorem ipsum dolor sit amet consectetur adipisicing elit. Suscipit libero sapiente,
                minus atque a nesciunt ipsum? Illum sapiente odio provident maxime aut nihil voluptatem officia voluptatibus vel! Necessitatibus, ipsam esse. Lorem ipsum dolor sit amet consectetur adipisicing elit. Suscipit libero sapiente, minus atque
                a nesciunt ipsum? Illum sapiente odio provident maxime aut nihil voluptatem officia voluptatibus vel! Necessitatibus, ipsam esse.
            </p>
        </div>
    </div>

    <!--xBlog Detailx-->

What I’m trying to achieve is when I click the thumbnail title and when directed I want the blog-content.html to show the value that I input from blog.html using innerHTML

I’ve tried to use module.exports, script type=”module” and importing both js files in blog-detail.html but nothing work 🙁

and I’ve tried to browse for more solutions but my English isn’t very good for browsing, I don’t know the keyword to search for more solutions.

Sorry for the long question, Thanks.

How to fix Uncaught TypeError: Cannot read properties of null (reading ‘addEventListener’)

I am adding an event listener to an HTML element, so that when you click on it the drop-down displays, but for some reason, I get the Uncaught TypeError: Cannot read properties of null (reading 'addEventListener') error, I am not sure how to fix that?

HTML el code

 <li class = "nav-item projects">
  <a class ="nav-link" href="#">Projects
   <img class = "down-arrow" src="images/icons/down_arrow_icon.png" alt="Down_arrow_icon">
  </a>
</li>

 <div class ="project-list">
      <ul class="flex-column">
        <li class="project-item ">Calculator App</li>
        <li class="project-item">Vending Machine App</li>
        <li class="project-item">Landing Page</li>
      </ul>
    </div>

I have separated the project-list from the main list as it is a separate element on its own.
The nav-item projects is part of a nav,but i am only using that part of the nav for the javascript eventListener

JS event listener

let projects = document.querySelector(".projects");
let projectList = document.querySelector(".project-list")

projects.addEventListener('click', function handleMouseOver(){
    if(projects){
        projectList.style.display = "block"
    }
})

I have the

how to fix this onclick error?? (javascript) [duplicate]

i was following youtube tutorial for deleting messages in chat and i did the same thing as he did and onclick doesnt work for me

const newMessage = ref(database, 'messages/');
        
function deleteMessage(self){
    console.log("test");
}
onChildAdded(newMessage, (data) =>  {
    let string = data.val().message;
    string = string.replaceAll("<", "&lt").replaceAll(">", "&gt");
    let msgDiv = '<message>n' + data.val().time + " / " + data.val().name + ": " + string + '<delete>' + '<button onclick="deleteMessage(this);">' + '<span class="iconify" data-icon="ant-design:delete-filled"></span>' + 'Usuń' + '</button>' + '</delete>' + '</message>'
    let messages = document.querySelector("messages");
    messages.innerHTML += msgDiv;
})

i got: Uncaught ReferenceError: deleteMessage is not defined
at HTMLButtonElement.onclick ((index):1:1)

any solutions?

How can you read POST data from a javascript XMLHttpRequest in Golang?

Here’s the javascript function called:

function cwk_submit_form() {
   var form = document.getElementById("FORM_ID")
   var XHR = new XMLHttpRequest();


   const FD = new FormData( form );
   for (const element of FD.entries()) {
       console.log(element)
   }

   XHR.open( "POST", "http://localhost:8080/post_data" );
   XHR.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

   XHR.send( FD );
}

I left the console.log in there to mention that this does print out the correct data, meaning that the issue is seems to be in how the data is transferred.

The Golang code that receives the response is:

func post_data(w http.ResponseWriter, r *http.Request) {
    log.Println("post was called")

    r.ParseForm()
    for key, value := range r.Form {
        log.Printf("%s = %sn", key, value)
    }
}

Nothing is printed by this for loop.

If I use an HTML Form to submit like so:

<form action="//localhost:8080/post_data" method="POST">
    <input type="text" name="field1" value="" maxLength="20"/>
        
    <input type="text" name="field2" value="" maxLength="20"/>
        
    <input type="submit" value="Sign in"/>
</form>

then the Golang code above works fine, which leads me to believe that the XMLHttpRequest format is the issue.

How do I prevent an event from triggering during a GSAP animation?

I have a GSAP animation like this:

window.addEventListener('keydown', ()=>{
     GSAP.to(this.box, {
     x: this.box.position.x + 4,
     duration: 1,
    }
});

I want to increment the box’s x position by multiples of 4, and my current code above works, but only if the user waits until 1 second has passed before pressing another key. Then it goes 0 -> 4 -> 8 etc.

If they don’t wait a second, what happens is something like 0 -> 3.76 -> 6.45. These numbers change depending on how long a user waits before they press another key. This makes sense because I’m effectively cancelling the animation and using the current position (since 1 second hasn’t passed yet, it wouldn’t get to 4 yet) and then just rerunning the animation with the current position (that wasn’t 4).

Essentially, I want to prevent the ‘keydown’ event listener from triggered until the 1 second animation has been fully completed.

How would I do that?

This is what I’ve tried:

window.addEventListener('keydown', ()=>{
     if(this.prevent === false){
         this.prevent = true;
         GSAP.to(this.box, {
         x: this.box.position.x + 4,
         duration: 1,
         onComplete: ()=>{this.prevent = false}
        }
    }
});

But it does not work, if a user holds down a key it still does the wrong numbers.

Decrypt AES 256 CBC using crypto-js

i have the following key to decrypt erUF9SRCNQZPCBezVGzYYnUVgwAKZTvXzS5Zhgw6B/4= into “54545fwfwefweffvfdv”, I tried searching for similar question but the lack of my knowledge in encryption prevent me from solving this from my own.

function getDecryptedCode() {
var key = CryptoJS.enc.Utf8.parse('JM@q@MM8AAxVV');
var iv = CryptoJS.enc.Utf8.parse('');
var ciphertext = CryptoJS.enc.Base64.parse("erUF9SRCNQZPCBezVGzYYnUVgwAKZTvXzS5Zhgw6B/4=");
var encryptedCP = CryptoJS.lib.CipherParams.create({
  ciphertext: ciphertext,
  formatter: CryptoJS.format.OpenSSL
});
var decryptedWA = CryptoJS.AES.decrypt(encryptedCP, key, {
  iv: iv
});
var decryptedUtf8 = decryptedWA.toString(CryptoJS.enc.Utf8);

return decryptedUtf8;

}

console.log(getDecryptedCode());

I’m trying to exclude elements from an Array, but I’m doing somthing wrong

I’m trying to create this script: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/seek-and-destroy

After the comment “Verify and delete” is where I have the problem.
I try to check all the elements form the array ‘theCheck’ with the elements from ‘destroyers’ and if the elements dont match then the script will push that value to the output array.

But it pushes every element regardless.

Expected output value: [1,1]

Current output value value: [1,2,3,1,2,3]

function destroyer(arr) {

  let theCheck=[];
  let destroyers = [];
  let output = [];


  for(let i = 1;i<arguments.length; i++){
    destroyers.push(arguments[i]);
  }
  for(let i = 0; i<arguments[0].length; i++){

    theCheck.push(arguments[0][i])
  }
//Verify and delete

  var j = 0
  for(let i = 0; i < theCheck.length; i++){



    for(j = 0 ; j < destroyers.length; j++){


      if(theCheck[i] !== destroyers[j]){
        output.push(theCheck[i])
        break;
      }
    }
  }

  console.log(theCheck)
  console.log(destroyers)
  console.log(output)
  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);

Middleware “strapi::session”: App keys are required. Please set app.keys in config/server.js (ex: keys: [‘myKeyA’, ‘myKeyB’])

Trying to set up strapi and cloudinary
I watched two videos and they are all OK, but I have an error, tell me why?

Middleware “strapi::session”: App keys are required. Please set
app.keys in config/server.js (ex: keys: [‘myKeyA’, ‘myKeyB’])

enter image description here

plugins.js

module.exports = ({ env }) => ({
  // ...
  upload: {
    config: {
      provider: 'cloudinary',
      providerOptions: {
        cloud_name: env('CLOUDINARY_NAME'),
        api_key: env('CLOUDINARY_KEY'),
        api_secret: env('CLOUDINARY_SECRET'),
      },
      actionOptions: {
        upload: {},
        delete: {},
      },
    },
  },
  // ...
});

.env

HOST=0.0.0.0
PORT=1337
CLOUDINARY_NAME="my data"
CLOUDINARY_KEY="my data"
CLOUDINARY_SECRET="my data"
JWT_SECRET=my data

server.js

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337),
  app: {
    keys: env.array('APP_KEYS'),
  },
});

middlewares.js

module.exports = [
  'strapi::errors',
  'strapi::security',
  'strapi::cors',
  'strapi::poweredBy',
  'strapi::logger',
  'strapi::query',
  'strapi::body',
  'strapi::session',
  'strapi::favicon',
  'strapi::public',
];

admin.js

module.exports = ({ env }) => ({
  auth: {
    secret: env('ADMIN_JWT_SECRET'),
  },
  apiToken: {
    salt: env('API_TOKEN_SALT'),
  },
});

algorithm to match players

I’ve been working on a site that can match players together recently and I can’t figure out what the best way to go about the algorithm would be. All players that try to play are assigned a unique lobby that they are in, they can queue either solo or with someone else. For example we have and 2 on 2 game, 1 player enters the queue playing alone then 2 players enter the queue being in the same lobby(being in the same lobby means that when they get a match they will play on the same team) so currently there is 1 player queing solo and 2 players in a team, the total amount of players needed to to make a match would be 4, so a match wouldn’t be found yet, then another solo player enters the queue at this point he should get matched with the other solo player and face the 2 players in a team. Every lobby also has parameters for example gamemode and region and only the players with the same parameters can get matched against each other. There are at least 3 regions and 3 gamemodes for example 1 on 1, 2 on 2, 3 on 3 etc. Currently I am pushing all lobbies that enter the queue into an array

{
    "size":2,
    "id":"id",
    "region":"US",
    "mode":"2v2",
    "players":[
        {
            "username":"test1",
            "id":"id1"
        },
        {
            "username":"test2",
            "id":"id2"
            
        }
    ]
}

this is what one 2 on 2 lobby would look like and there can be thousands of these types of lobby in the array all searching for game. I am unsure of how I would make a algorithm that is the most effective and dynamic and would match all lobbies in the array even tho they have different parameters. I am using Node.js to accomplish this.

How do I add a role with discord.js? Using v13

Now, this has been asked a lot and I can’t seem to end up fixing my problem, here’s my current code

const role = message.guild.roles.cache.find(role => role.id == "Role ID")
const member = message.author
member.roles.add(role)

My problem is, it outputs this error:

                        member.roles.add(role);
                                     ^
TypeError: Cannot read properties of undefined (reading 'add')

What it seems to me, is that member.roles.add() is most likely not being able to properly add the role, its not .find() because when I console.log(role), it does show the Role object, does anyone know how to fix this? or is .add() discontinued in v13?

javascript error: Cannot read properties of null (reading ‘click’) [duplicate]

I am using this github repo https://github.com/derac/Auto-Apply-to-Dice to auto apply jobs on dice website looks like it is failing here https://github.com/derac/Auto-Apply-to-Dice/blob/master/apply.py#L154 I did tried many ways to resolve the error but no luck can someone help me.

Error :-

Applying to this job failed with error: Message: javascript error: Cannot read properties of null (reading 'click')

Thanks
Sri

Using google maps distance matrix API – javascript

I am trying to run teh example from here: “https://jsfiddle.net/3b03m5mt/”

Apparently, works when refreshing the page.
Using this code only in a project that I’ve created returns – “Error was: REQUEST_DENIED”.

Once it works, I will use it in a larger project, but need to understand why it fails.
Please help throubleshooting.

Thank you