I'm trying to create my own version of Snake, the arcade game, as a learning exercise. I've tried several versions of this function and had no success. What am I doing wrong?
This code is meant to create the snake at the beginning of the game, preferrably on page-load.
body {
position: relative;
display: flex;
justify-items: center;
align-items: center;
margin: 0;
background: rgb(150, 223, 255);
}
#game-board {
width: 100vw;
height: 100vh;
border: 5px solid darkgrey;
box-sizing: border-box;
}
button {
position: absolute;
}
.snake-block {
position: absolute;
width: 1vw;
height: 1vh;
background: purple;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Snake</title>
<link rel="stylesheet" href="/styles.css">
</head>
<body>
<div id="game-board">
<button>Start</button>
</div>
<script>
const babySnake = 1;
function createSnake(babySnake) {
while babySnake <= 3 || babySnake = false {
document.createElement("div");
div.setAttribute('class', 'snake-block');
snake-block.style.backgroundColor('salmon');
}
}
createSnake()
</script>
</body>
</html>