+ 1

Javascript?

Lets see this code: let box = document.querySelector("div"); let input = document.querySelector("input"); input.addEventListener(input. () = { box.style.border-radius = input.value; box.style.background-color = input.value; }) whats wrong here

20th Jun 2024, 9:45 PM
AdvancedPocky Official
AdvancedPocky Official - avatar
4 odpowiedzi
+ 1
in sololearn, js is placed inside head. So when that js code is getting interpreted div is not created. --> place code after body. or --> place code inside window.onload = (){here}
20th Jun 2024, 11:16 PM
Andrew [DEAD]
Andrew [DEAD] - avatar
+ 1
As andrew said you have to use this in your code. I made a minor correction: window.onload = () => {    //code here } After you put your JS code inside the  function, you'll get an error “box”  is not defined. To fix this, you need to give your div an ID. Like this: <div id="box"></div>
20th Jun 2024, 11:44 PM
Chris Coder
Chris Coder - avatar
+ 1
This will help you: //Lets see this code: let box = document.querySelector("div"); let input = document.querySelector("input"); input.addEventListener("input", () => { //box.style.border-radius box.innerText = "" box.style.borderRadius = input.value + "px"; //box.style.background-color box.style.backgroundColor = "#" + input.value + input.value + "9"; }) https://sololearn.com/compiler-playground/W8NAYkJYHzLa/?ref=app
21st Jun 2024, 12:03 AM
JaScript
JaScript - avatar
0
20th Jun 2024, 11:07 PM
Chris Coder
Chris Coder - avatar