Reputation: 19
Can anyone see where I am doing wrong? I'd like each function to run after each other. Is this even possible the way I am doing it? Thanks
<html>
<head>
<title>Java Script Test</title>
<script type="text/javascript">
function alertA() {
var name = prompt("What's your first name");
if (name.length < 13) {
alert("Hi Paul")
} else {
alert("Don't lie, your name is Paul");
}
}
function redirect() {
var r = confirm("Do you think Lee has learned JavaScript? If yes click OK")
if (r == true) {
window.location = 'http://www.youtube.com';
} else {
window.location = 'http://www.google.com';
}
}
</script>
</head>
<body>
<input type="button" value="Click me!" onClick="alertA()" />
</body>
</html>
Upvotes: 0
Views: 54
Reputation: 1000
You can simply call redirect()
at the end of function alertA(){...}
function alertA() {
var name = prompt("What's your first name");
if (name.length < 13) {
alert("Hi Paul")
} else {
alert("Don't lie, your name is Paul");
}
redirect() // <<<<<<<----- calling next function
}
function redirect() {
var r = confirm("Do you think Lee has learned JavaScript? If yes click OK")
if (r == true) {
window.location = 'http://www.youtube.com';
} else {
window.location = 'http://www.google.com';
}
}
You could also merge both functions into a single one:
function alertA() {
var name = prompt("What's your first name");
if (name.length < 13) {
alert("Hi Paul")
} else {
alert("Don't lie, your name is Paul");
}
var r = confirm("Do you think Lee has learned JavaScript? If yes click OK")
if (r == true) {
window.location = 'http://www.youtube.com';
} else {
window.location = 'http://www.google.com';
}
}
Upvotes: 1