Skip to content

Instantly share code, notes, and snippets.

@natafaye
Created February 10, 2022 04:57
Show Gist options
  • Save natafaye/68f7715d87f2b46a87c3994fbe7a7649 to your computer and use it in GitHub Desktop.
Save natafaye/68f7715d87f2b46a87c3994fbe7a7649 to your computer and use it in GitHub Desktop.
<!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>Document</title>
</head>
<body>
<script src="week2.js"></script>
</body>
</html>
var numberOfCats = prompt("How many cats do you have?");
numberOfCats = parseInt(numberOfCats);
if(numberOfCats === 3) {
alert("We can be friends.");
}
else if(numberOfCats === 4) {
alert("Come back when you have more cats");
}
else if(numberOfCats > 50) {
alert("You need help")
}
else {
alert("Go away!");
}
// for loop
for(var i = 0; i < numberOfCats; i++) {
console.log("I like your cat")
}
while(numberOfCats < 3) {
numberOfCats = numberOfCats + 1;
// numberOfCats += 1
// numberOfCats++
console.log("Here's another cat");
}
alert("Now you have " + numberOfCats + " cats")
// pick some number
var number = 7;
var guess;
// loop while they have the wrong answer
do {
// ask the user to guess what number you are thinking of
guess = prompt("Wrong answer. What number am I thinking of?");
guess = parseInt(guess);
} while(number !== guess)
// Tell them that they got the answer correct
alert("You did it!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment