make a number label in the top left of the screen with the size of medium and value of 0 and a square in the center with the size medium and whenever you click it the number value goes up by 1 in javascript

To make a number label in the top left of the screen, we can create a div element and add some CSS styles to position it in the top left corner. We can also set the initial value of the number label to 0.

index.tsx
const numberLabel = document.createElement('div');
numberLabel.style.position = 'absolute';
numberLabel.style.top = '0';
numberLabel.style.left = '0';
numberLabel.style.fontSize = 'medium';
numberLabel.textContent = '0';
221 chars
7 lines

To create a square in the center of the screen, we can also create a div element and add some CSS styles to position it in the center. We can also add an event listener that increments the number value by 1 every time it's clicked.

index.tsx
const square = document.createElement('div');
square.style.position = 'absolute';
square.style.top = '50%';
square.style.left = '50%';
square.style.transform = 'translate(-50%, -50%)';
square.style.width = 'medium';
square.style.height = 'medium';
square.style.backgroundColor = 'black';

square.addEventListener('click', () => {
  const currentValue = Number(numberLabel.textContent);
  numberLabel.textContent = currentValue + 1;
});
436 chars
14 lines

Finally, we can add both elements to the HTML body using the appendChild() method.

index.tsx
document.body.appendChild(numberLabel);
document.body.appendChild(square);
75 chars
3 lines

gistlibby LogSnag