Skip to content
Permalink
5d28269657
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
34 lines (28 sloc) 863 Bytes
<!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>Week 5 Exercise: 2</title>
</head>
<body>
<h1><code>Recursion Exercise</code></h1>
<script>
//Exercise 2
console.log("Exercise 2: Recursion")
function isEven (num) {
if (num == 0) { //alt way: (num % 2 == 0)
return true; //even #
} else if (num == 1) { //alt way: (num % 1 == 0)
return false; //odd #
} else if (num < 0) {
return isEven(-num); //negative #
}
else {
return isEven(num - 2); //any other numbers
}
}
</script>
</body>
</html>