Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Javascript Basics If statements
var maxHealth = 100 var currentHealth = 50; var healAmount = 10; function heal() { var newHealth = currentHealth + healAmount; currentHealth += healAmount; currentHealth = newHealth > 100 ? maxHealth : newHealth; return (currentHealth / maxHealth) * 100; } var result = heal(); // currentHealth - 60 heal(50); // currentHealth = 110 but maxHealth = 100, therefore currentHealth = 100 var keyPressed ="l"; var xPos = 0; let endPos = 5; //if (keyPressed == "r" && xPos < endPos) { xPos +=1;} <-- If statement when both need to be true if (keyPressed == "r") { xPos += 1; } else if (keyPressed == "l") { xPos -= 1; } else { xPos =0; } print(result);
run
|
edit
|
history
|
help
0
Triangle
Javascript Basics
class Queue
Tiny Hannoi
braille renderer, in javascript
Try
p
Dum
H
Arrays