+ 1

Someone please help me with my js code

I'm trying to do an arcade game and someth went wrong. The duck doesn't react when I click on it. Code - https://code.sololearn.com/WkbB0m6Y6vt9/?ref=app

19th May 2020, 1:46 PM
_🐻_
_🐻_ - avatar
5 Réponses
+ 6
https://code.sololearn.com/W7n19fii5cf9/?ref=app _🐻_ I fixed the code. A lot of fixing needed, marked all the changed lines.
19th May 2020, 2:18 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 5
//добавляем обработчик событий //Get the target element const duck = document.querySelector("#duck"); //Add the click event listener duck.addEventListener("click", () => { //Dont forget to call the functions here increaseScore(); moveDuck(); }); //функция увелечения текущего //increase score by 1 const increaseScore = () => { //get the content of the targetn element. the current value for score const scoreHTML = document.querySelector("#score-counter").innerHTML; //get the element to insrease the value const score = document.querySelector("#score-counter"); //cast the score value to Number Type let count = Number(score); //set the new score to the target element scoreHTML.innerHTML = count +1; } //функция перемещения утки в случайное место //get a random nubmer const getRandomNum = (num) => { return Math.floor(Math.random() * Math.floor(num)); } //move duck random const moveDuck = () => { const w = window.innerWidth; const h = window.innerHeight; duck.style.top = getRandomNum(w) + "px"; duck.style.left = getRandomNum(h) + "px"; you had some syntax errors. such as 'increasescore' instead of 'increaseScore', and 'Math.Floor' instead of 'Math.floor'. the duck now randomly spawns in different locations. you still need to think the score, and where the duck should spawn functionalities
19th May 2020, 2:08 PM
Sebastian Pacurar
Sebastian Pacurar - avatar
+ 3
please post the code link so we can debug it easier
19th May 2020, 1:49 PM
Sebastian Pacurar
Sebastian Pacurar - avatar
+ 1
fixed post and add the link
19th May 2020, 1:52 PM
_🐻_
_🐻_ - avatar
0
Thanks a lot! This is my first work with js and I was very inattentive. But I still don't understand how to make the duck show in random places in the background picture?
19th May 2020, 2:35 PM
_🐻_
_🐻_ - avatar