Last active
December 17, 2017 22:39
-
-
Save qaisarmehmood/80cc157979528bba985420d175e4df14 to your computer and use it in GitHub Desktop.
ASSIGNMENT 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Assignment 5</title> | |
</head> | |
<body> | |
<h1>Questions</h1> | |
<p> | |
a. Name the new function myNewFunction() ? | |
function myNewFunction(){ | |
}; | |
</p> | |
<p> | |
b. Write a for loop from 1 to 100, loop must iterate 100 times, not 99 or 101 times | |
for (i = 1; i <= 100; i++) { | |
console.log); | |
} | |
</p> | |
<p> | |
c. Within the for loop, use a series of if, else if, and else statements to evaluate if the remainder of the iteration divided by a particular number is zero | |
for (i = 1; i <= 100; i++) { | |
if (i % 2 == 0){ | |
console.log("even"); | |
} | |
else if (i % 2 == 1){ | |
console.log(“odd”); | |
} | |
else { | |
console.log(i); | |
} | |
} | |
</p> | |
<p> | |
d. Let the value of the iteration be a variable (var) named i: | |
i. If i % 3 == 0 && i % 5 == 0, use the function console.log(“Hello World”) | |
ii. Else if i % 3 == 0, console.log(“Hello”) | |
iii. Else if i % 5 == 0, console.log(“World”) | |
iv. Else console.log(i) | |
var i; | |
for (i = 1; i <= 100; i++) { | |
if (i % 3 == 0 && i % 5 == 0){ | |
console.log("Hello World"); | |
} | |
else if (i % 3 == 0){ | |
console.log("Hello"); | |
} | |
else if (i % 5 == 0){ | |
console.log(“World”); | |
} | |
else { | |
console.log(i); | |
} | |
} | |
} | |
</p> | |
<p> | |
e. Call myNewFunction()? | |
myNewFunction(); | |
( to call our function we just have to use this command or we can add a button | |
<button onclick="myNewFunction()">Run Script</button> ) | |
</p> | |
<p> BONUS QUESTION | |
</p> | |
<br> | |
<script type="text/javascript"> | |
function myNewFunction(x){ | |
var i=x; | |
for(vari=x; i<=100; i++){ | |
console.log(i); | |
} | |
myNewFunction(x); | |
</script> | |
</body> | |
</html> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment