Zur welcher programmier sprache gehört der code?
var ball = document.createElement('div');
ball.style.width = '50px';
ball.style.height = '50px';
ball.style.backgroundColor = 'red';
ball.style.borderRadius = '50%';
ball.style.position = 'absolute';
ball.style.top = '0px';
ball.style.left = '0px';
document.body.appendChild(ball);
var x = 0;
var y = 0;
var xSpeed = 1;
var ySpeed = 1;
var sound = new Audio('https://www.myinstants.com/media/sounds/mario-coin-sound-effect.mp3');
function moveBall() {
x += xSpeed;
y += ySpeed;
ball.style.left = x + 'px';
ball.style.top = y + 'px';
if (x > window.innerWidth - 50) {
xSpeed = -1;
sound.play();
}
if (y > window.innerHeight - 50) {
ySpeed = -1;
sound.play();
}
if (x < 0) {
xSpeed = 1;
sound.play();
}
if (y < 0) {
ySpeed = 1;
sound.play();
}
}
setInterval(moveBall, 10);
2 Antworten
Vom Fragesteller als hilfreich ausgezeichnet
Von gutefrage auf Grund seines Wissens auf einem Fachgebiet ausgezeichneter Nutzer
Informatikkaufmann
Hallo Prototuep,
ich hätte auch die schnelle JavaScript gesagt
Ben
JavaScript