+ 1
Someone please help me with JavaScript.
Please help me with this code I wants to make buttons that can move the box up or down but i think i stuck someone please help https://code.sololearn.com/WBrSBCLn5ZCM/?ref=app
2 Antworten
+ 2
// Umair Ansari , hope this helps
const box = document.getElementById("box");
const upBtn = document.getElementById("btn1");
const downBtn = document.getElementById("btn2");
var pos;
window.onload = function(){
    upBtn.onclick = moveUp;
    downBtn.onclick = moveDown;
    box.style.top = "150px";
    pos = 150;
    ChkPos();
}
function moveUp(){
    pos-=50;
    if (pos<=0) pos=0;
    box.style.top = pos+"px";
    ChkPos();
}
function moveDown(){
    pos+=50;
    if (pos>=300) pos=300;
    box.style.top = pos+"px";
    ChkPos();
}
ChkPos = () => {         
    upBtn.disabled = pos<=0;  
    downBtn.disabled = pos>=300; 
}
https://www.sololearn.com/compiler-playground/WzhmlHIus5Iw
0
Can you make a code this is not working I think I did something wrong



