How to convert Khan academy code to p5.js

I’m using the https://editor.p5js.org/Josef37/sketches/RGDv9lHkK for convert to p5.js and I’m still don’t know how to convert 100% correct, the picture won’t show up when i convert myCode from the khanAcademy Original code to p5.js and can you also help me put the sound clack.wave when Block fall down in my code as well?

myCode

function preload() {
  blockImg = loadImage('block.png');
}

var Block = function(x, y) {
    this.x = x;
    this.y = y;
    this.img = loadImage("block.png");
    this.sticks = 0;
};


  
  
function setup() {
  createCanvas(windowWidth, windowHeight);

Block.prototype.draw = function() {
    image(this.img, this.x, this.y, 40, 40);
};
  
Block.prototype.hop = function() {
    this.img = getImage("block.png");
    this.y -= -44;
};

Block.prototype.fall = function() {
    this.img = getImage("block.png");
    this.y += 5;
};
}



function draw() {
  background(200);

var block = new Block(10, 300);
block.draw();

}

I’m using P5.js on this website >https://editor.p5js.org/Josef37/sketches/RGDv9lHkK<

https://www.khanacademy.org/computing/computer-programming/programming-games-visualizations/side-scroller/a/beaver-character
Original Code from KhanAcademy

var Beaver = function(x, y) {
    this.x = x;
    this.y = y;
    this.img = getImage("creatures/Hopper-Happy");
    this.sticks = 0;
};

Beaver.prototype.draw = function() {
    image(this.img, this.x, this.y, 40, 40);
};

Beaver.prototype.hop = function() {
    this.img = getImage("creatures/Hopper-Jumping");
    this.y -= -44;
};

Beaver.prototype.fall = function() {
    this.img = getImage("creatures/Hopper-Happy");
    this.y += 5;//Down Gavity
};


var beaver = new Beaver(10, 300);
beaver.draw();

I am making a counter in javascript. Can someone tell me how to ‘loop’ here so that the counter could increase everytime somone clicks the button

let count = document.querySelector(“.count”);

let dropBtn = document.querySelector(“.btn-drop”);

let resetBtn = document.querySelector(“.btn-reset”);

let addBtn = document.querySelector(“.btn-add”);

addBtn.addEventListener(“click”, function () {

let add = 0;

for (let i = 0; i ; i++) count.textContent = add += 1;

});

Javascript array value is undefined inside loop

I am trying to compare two objects. If an item inside checkedList is also found inside savedList i would like to copy the first item in the array from checkedList and place it with the found item in savedList. If items inside the checkedList is not found in the savedList I want to add the entire item to savedList. I dont wish to keep the same item twice inside the savedList. I am using the pop/push method to do this.

Problem I am running into is inside the [ while->for loop].
Uncaught TypeError: Cannot read properties of undefined (reading ‘1’)
When an item is found inside the savedList I wish to make the necessary alteration then move to the next item via pop(). However,
when I use the pop() method the previous item is lost. Below is my working code as well as a link to JSFiddle.

Desired Output:
savedItemList = {
“listName”: “List_daily:Daily Get From Back List”,
“date”: “”,
“itemList”: [
[ 11, 888 ], [ 55, 227 ], [ 44, 236 ],
[ 3, 700 ], [ 2, 600 ]
]
};

var savedItemList = {
    "listName": "List_daily:Daily Get From Back List",
    "date": "",
    //itemList contains [item quantity, item ID]
    "itemList": [
      [  1, 888 ], [  2, 227 ],  [  3, 236 ],
      [  3, 700 ],  [  2, 600 ]
    ]
};

var checkedItemList = [
    //itemData contains [item quantity, item ID]
    { "rowNumber": 1,  "itemData": [ 11, 888 ]  },
    { "rowNumber": 4,  "itemData": [ 44, 236 ]  },
    { "rowNumber": 3,  "itemData": [ 55,  227]  }
];

function moveItemsToList(savedItemList, checkedItemList)
{
  //while checkedItemList length is not zero
     while(checkedItemList.length)
     {
     //pop the last element inside checkedList
         var temp = checkedItemList.pop().itemData;
     //loop through the items inside savedList
     for(let k=0; k < savedItemList.itemList.length; k++)
        {
      //compare temp[1] itemID with savedList itemID
            if(temp[1] == savedItemList.itemList[k][1])
            {
        //if found save the quantity from temp[0] variable to savedItemList 
                savedItemList.itemList[k][0] = temp[0];
        //then move onto the next item on checkedList
                temp = checkedItemList.pop();
            }
        }
     //if items from CheckedList not Found in savedList        //Add the item and its quantity to savedList
        savedItemList.itemList.push(temp);
            
     }
     console.log(savedItemList);    
     
}

moveItemsToList(savedItemList, checkedItemList);

Need to add 30 minutes timer into if condition using Js

I have ecommerce website. In that for same day delivery need to order before 11. So before 30 minutes of the end time(i.e. 11) i want to show that timer section.
Below code I am trying But getting issue how to set timer functionality.

setInterval(function(){
    var secs = 1800;
    var date = new Date;
    // date.setTime(result_from_Date_getTime);

    var seconds = date.getSeconds();
    var minutes = date.getMinutes();
    var hour = date.getHours();

    console.log("Hour"+hour+"Minutes"+minutes+"seconds"+seconds);
    // console.log(minutes);
    // console.log(seconds);
    if(hour == 9 && minutes>=30)
    {
        var mins = secs / 60;
        console.log("Timer"+mins);
        $('.top-header-content1').removeClass('hide-ticker1');
        
    }
    secs--;
    else if (hour >= 10){
        console.log("hii11");
        $('.top-header-content1').addClass('hide-ticker1'); 
    }
    },1000);

If anyone have a idea , how to add time please let me know

how to only change a specific query params in react

Suppose I have this url:
/app/search?spaceId=**621cd16015**&resource_type=room&capacity=3

and I want to update only the spaceId based on click, so the new URL will be:
/app/search?spaceId=**14235ad**&resource_type=room&capacity=3

I’m using the class component. I used the following code to change the spaceId. It works, but it also removes all the other parameters too.

this.props.history.push({
      pathname: "/app/search",
      search: `?spaceId=${event}`,
    });

Pagination(JS/SQL/PHP)—How to select fixed-length subset of the general results to display in a single page

Parameters:
1.Items per page (offset): indicates how many posts display in a single page. For now, this will be a static number, but may later become an item in preferences.

2.Page number: determines how many multiples of the offset we exclude from the result set before selecting items.

3.Post list:

Return: array of results associated with the selected ids, to be parsed in JS.

Notes: this will be split into two parts. The first, in JS, will collect the relevant ids from the general list provided by the list retrieval function, and use an AJAX call to send them as an array to a PHP page. The PHP will cycle through these ids and pull the associated data from the database, returning an array of results that’ll be parsed by the JS.

Please, could anyone hep me with this why I am getting this error Uncaught

    here is my code 

This is the data.js
//data.js//

    export default {
        product: [
            {
                _id: '1',
                name: 'Short Women Gown',
                category: 'Shirts',
                image: '/images/product-1.jpg',
                price: 60,
                brand: 'Hiskywin',
                rating: 4.5,
                numReviews: 10,
                coutInStock: 6
            },
            {
                _id: '2',
                name: 'Nighty Women Gown',
                category: 'Gown',
                image: '/images/product-2.jpg',
                price: 89,
                brand: 'Nike',
                rating: 3.5,
                numReviews: 9,
                coutInStock: 90
            },
            {
                _id: '3',
                name: 'Mimi lilly Club Gown',
                category: 'Women',
                image: '/images/product-3.jpg',
                price: 100,
                brand: 'Champion',
                rating: 5.0,
                numReviews: 5,
                coutInStock: 6
            },
            {
                _id: '4',
                name: 'Short Women Gown',
                category: 'Shirts',
                image: '/images/product-4.jpg',
                price: 30,
                brand: 'Hiskywin',
                rating: 4.5,
                numReviews: 12,
                coutInStock: 6
            },
            {
                _id: '5',
                name: 'Short Women Gown',
                category: 'Shirts',
                image: '/images/product-5.jpg',
                price: 55,
                brand: 'Hiskywin',
                rating: 3.5,
                numReviews: 16,
                coutInStock: 6
            },
            {
                _id: '6',
                name: "African Queen's Fashion Waer",
                category: 'Swears',
                image: '/images/product-6.png',
                price: 97,
                brand: 'African',
                rating: 4.5,
                numReviews: 15,
                coutInStock: 6
            },
        ],
    };
    
    

This is where I create the and export as an object with render() method
//HomeScreen.js//

    import data from '../data.js'; 
    const HomeSreen = {
        render: () =>{
            const { products } = data;
            return `
            <ul class="products">
                ${products.map(
                    (product) => `  
                <li>
                    <div class="product">
                        <a href="/#/products/${product_id}">
                            <img src="${product.image}" alt="${product.name}">
                        </a>
                    <div class="produt-name">
                        <a href="/#/products/1">
                            ${product.name}
                        </a>
                        </div>
                    <div class="product-brand">
                        ${product.brand}
                    </div>
                    <div class="product-price">
                        $${product.price}
                    </div>
                    </div>
                </li>
                `
                )}
            `;
            
        },
    };
    export default HomeSreen;
    
    

Lastly app.js where I create router function and innerHTML to HomeScreen render then set load event of window to router function

    enter code here
    //app.js//

    import HomeSreen from "./screens/HomeScreen.js";

const router = () =>{
    const main = document.getElementById('main-container')
    main.innerHTML = HomeSreen.render();
};
window.addEventListener("load", router )

Have tried many ways to solve this but can’t find solution to it, please I need help n this

is there any way to usestate respond immediately?

I was wanting to get value from the my server of the node with the usestate, but it returns the empty array value first and then pops up the value of my axios

has any way of the value of the axios appears first than that of the empty array ?

my code:

const [valTop, valTopstate] = useState([])

    async function MusicTop() {
        axios("http://localhost:3001/")
        .then(res=>{
            valTopstate(res.data.tracks.data)
        })
    }
    
    useEffect(()=>{
        MusicTop()

    }, [valTop])

div doesn’t have the same height when i’m usingmy phone but not on my pc

Hi everybody i got a problem when i open this page on my pc everything looks ok, it’s also ok with the google responsive mode but when i open this page on my phone the height is not the same for each screenshot of the rendering
capture of my pc

You can also see it at : https://loganthenard.tk/testvid/index

        let startX, scrollLeft, isDown = !1;
        const slider = document.querySelector(".items"),
            end = () => {
                isDown = !1, slider.classList.remove("active")
            },
            start = e => {
                isDown = !0, slider.classList.add("active"), startX = e.pageX || e.touches[0].pageX - slider.offsetLeft, scrollLeft = slider.scrollLeft
            },
            move = e => {
                if (!isDown) return;
                e.preventDefault();
                const t = (e.pageX || e.touches[0].pageX - slider.offsetLeft) - startX;
                slider.scrollLeft = scrollLeft - t
            };
        slider.addEventListener("mousedown", start), slider.addEventListener("touchstart", start, {passive: true}), slider.addEventListener("mousemove", move, {passive: true}), slider.addEventListener("touchmove", move, {passive: true}), slider.addEventListener("mouseleave", end, {passive: true}), slider.addEventListener("mouseup", end, {passive: true}), slider.addEventListener("touchend", end, {passive: true});
.wrapper-comment {
position: relative;
display: flex;
align-items: center;
padding: 25px 0;
background-color: white;
flex-direction: column;
align-content: center;
justify-content: center;
}


.items {
position: relative;
width: 100%;
overflow: hidden;
white-space: nowrap;
cursor: pointer;
height: 250px;
}
.items.active {
cursor: grab;
}

.item {
display: inline-block;
margin-left: 15px;
user-select: none;
width: 50%;
min-width: 225px;
height: 250px;
color: #000;
font-weight: bold;
}

.item p {
margin: 15px 10px;
font-size: 15px;
white-space: pre-line;
}

.item:last-child {
margin-right: 20px;
}

@media screen and (max-width: 400px) {
.slide-text {
  font-size: 0.7em;
}
}


@media screen and (min-width: 500px) {
.item {
  width: 33%;
}
.slide-text {
  font-size: 1.5em;
}
}
@media screen and (min-width: 800px) {
.item {
  width: 25%;
}
}
@media screen and (min-width: 1200px) {
.wrapper-comment {
  margin-left: -20px;
  padding: 25px 100px;
}
.item {
  width: 20%;
}
.slide-text {
  margin-left: 30px !important;
}
}

@media screen and (max-width:1200px) {
.item p {
  font-size: 12px;
}
}

legend {
font-size: 15px;
margin-left: 10px;
font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
font-weight: 100;
}

.slide-text {
text-transform: uppercase;
white-space: nowrap;
margin-left: 10px;
}

hr {
border: 1px solid #000;
}

.star-rate {
display: flex;
justify-content: center;
}

.star-rate img {
width: 20px;
margin-top: 10px;
}
        <div class="wrapper-comment">
            <div class="slide-text">
                <h3>Les avis de</h3>
                <hr>
                <h3>Nos clients</h3>
            </div>
            <div class="items">
                <fieldset class="item">
                    <legend>Ashley</legend>
                    <div class="star-rate"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> <img src="img/star-solid.svg" width="20"
                            height="20" alt="star"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> </div>
                    <p>Jemsky est un éducateur sportif très agréable, à l'écoute et très pédagogue. Il a su adapté le cours a mon niveau, c'est exactement ce que je recherchais. Je recommande fortement ce coach.</p>
                </fieldset>
                <fieldset class="item">
                    <legend>Pénélope</legend>
                    <div class="star-rate"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> <img src="img/star-solid.svg" width="20"
                            height="20" alt="star"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> </div>
                    <p>Très bon coach! Nous avons demandé à Jemsky de faire un cours de sport dans notre entreprise. L'expérience à été parfaitement réussi et les collaborateurs étaient ravis! Je recommande vivement.</p>
                </fieldset>
                <fieldset class="item">
                    <legend>Hoai Anh</legend>
                    <div class="star-rate"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> <img src="img/star-solid.svg" width="20"
                            height="20" alt="star"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> </div>
                    <p>J'ai bien aimé le cours</p>
                </fieldset>
                <fieldset class="item">
                    <legend>Vincent</legend>
                    <div class="star-rate"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> <img src="img/star-solid.svg" width="20"
                            height="20" alt="star"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> </div>
                    <p>Jemsky à été mon coach pendant 1 ans, malheureusement suite à mon déménagement on a dû arrêter, mais je me suis jamais senti aussi bien que pendant ses 1 an avec mon coach. En plus des résultats, il a réussi à me redonner confiance en moi via le sport et la motivation, et surtout le sourire et la bonne humeur à chaques séances. Merci Coach</p>
                </fieldset>
                <fieldset class="item">
                    <legend>Maimouna</legend>
                    <div class="star-rate"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> <img src="img/star-solid.svg" width="20"
                            height="20" alt="star"> <img src="img/star-solid.svg" width="20" height="20" alt="star"> </div>
                    <p>Très professionnel et à l'écoute, je suis très contante d'avoir fait une séance avec Jemsky. Je le recommande vivement.</p>
                </fieldset>
            </div>

Having problems with npm installing yo

npm WARN deprecated [email protected]: this library is no longer supported

npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.

npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142

changed 873 packages, and audited 874 packages in 21s

58 packages are looking for funding
run npm fund for details

15 vulnerabilities (13 moderate, 2 high)

To address issues that do not require attention, run:
npm audit fix

To address all issues (including breaking changes), run:
npm audit fix –force

Run npm audit for details.