0
I’m trying to fix it, but I’m struggling, I don’t know what I’m doing wrong.
Create a button that when clicked creates a new element on screen with the shape of a red square with 100px of height and width. Whenever the button is clicked a new square should appear on the screen.
<div id="app">
<button class="botao">Adicionar</button>
<div class="box">
</div>
</div>
<script>
var btnElement = document.querySelector('button.botao').addEventListener("click", criarQuadrado);
var newQuadrado = document.querySelector('div.box');
newQuadrado.style.backgroundColor = red;
newQuadrado.style.width = 100;
newQuadrado.style.height = 100;
function criarQuadrado() {
btnElement.createElement(newQuadrado);
}
</script>
In your code you only have
red
(who in this case is acting as a identifier which, as it is not defined, will launch aReferenceError
variable not defined). You must use a string, that is to say,"red"
(which is, in fact, a "text", and not an identifier).– Luiz Felipe