+ 2

Placing a div in a random position on a website.

Hey, everyone! The code I'm currently working on has a long way to go, and is far from ANY game whatsoever. So, long story short: I'm trying to place a div(the little green ball) to a random position, and I'm getting all sorts of "Uncaught Type of null" errors and such. I'm looking for a way to do this with pure JavaScript (no jQuery). Please, help! https://code.sololearn.com/WlniPeYGJo0M/?ref=app

8th Jul 2020, 2:57 PM
Vasilis Karapas
Vasilis Karapas - avatar
3 Respostas
+ 4
You are selecting food class by document.querySelector("food") Corrected : document.querySelector(".food")
8th Jul 2020, 3:03 PM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
+ 3
Use dot (.) for class selectors Line 13 should be document.querySelector(".food")
8th Jul 2020, 3:04 PM
Ore
Ore - avatar
+ 3
Oops... :D Forgot about that part. Thanks you! ^_^
8th Jul 2020, 3:06 PM
Vasilis Karapas
Vasilis Karapas - avatar