Candy

In this example below you will see how to do a Candy with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by ovdojoey, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright ovdojoey ©
  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Candy</title>
  
  
  
  
  
</head>

<body>

  
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/ovdojoey/candy-LjmZPm */
var k = [7,3,9,1,5,9,10,12,4,5,6,5,4,3,1,6],
    c = [];

c.push(1);

for (var i = 1; i < k.length; i++) {
  if (k[i] > k[i-1]) {
    c.push(c[i-1] + 1)
  } else {
    c.push(1);
  }
}

for (var i = k.length - 2; i >= 0; i--) {
  if (k[i] > k[i+1]) {
    c[i] = Math.max(c[i], (c[i+1] + 1))
  }
}

document.write(c);

Comments