Skip to content

Instantly share code, notes, and snippets.

@natafaye
Created August 13, 2021 02:56
Show Gist options
  • Save natafaye/59e6912676671752f68b7fb291a9eb81 to your computer and use it in GitHub Desktop.
Save natafaye/59e6912676671752f68b7fb291a9eb81 to your computer and use it in GitHub Desktop.
function getAnswer(question) {
const answer = prompt(question);
return answer;
}
function start() {
let name = getAnswer("What is your name?")
alert("Hello " + name)
name = getAnswer("What is your name?")
alert("Hello " + name)
let hometown = getAnswer("Where are you from?")
alert(hometown + " is a great place!")
}
function setName(animal) {
const name = prompt("What is the name of your " + animal.type + "?");
animal.name = name;
}
function start() {
let cat = {
color: "brown",
type: "cat"
}
setName(cat);
let dog = {
color: "red",
type: "dog"
}
setName(dog);
alert("Cat named: " + cat.name);
alert("Dog named: " + dog.name);
}
function addVote(animal, voteList) {
voteList.push(animal);
}
function displayVotes(voteList) {
alert(voteList.join(", "));
}
function start() {
let voteList = [];
let vote = prompt("What is your vote?");
addVote(vote, voteList);
vote = prompt("What is your vote?");
addVote(vote, voteList);
vote = prompt("What is your vote?");
addVote(vote, voteList);
displayVotes(voteList);
}
<!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>
<button onclick="start()">Start</button>
<script src="week3.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment