JS midterm study
This commit is contained in:
@@ -132,6 +132,41 @@
|
|||||||
</ul>
|
</ul>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
<h2>JavaScript Global Functions</h2>
|
||||||
|
<ol>
|
||||||
|
<li>Describe the operation and the return for the following global functions:</li>
|
||||||
|
<ul>
|
||||||
|
<li>parseInt(number)</li>
|
||||||
|
<li>parseFloat(number)</li>
|
||||||
|
</ul>
|
||||||
|
</ol>
|
||||||
|
<p>Answers:</p>
|
||||||
|
<ul>
|
||||||
|
<li>parseInt(number) takes a string as input and returns the first integer in the string. Can also accept a
|
||||||
|
radix option</li>
|
||||||
|
<li>parseFloat(number) takes a string as input and returns the first float value in the string.</li>
|
||||||
|
</ul>
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<h2>JavaScript String Methods</h2>
|
||||||
|
<ol>
|
||||||
|
<li>Describe the operation and the return for the following String methods.</li>
|
||||||
|
<ul>
|
||||||
|
<li>length</li>
|
||||||
|
<li>toLowerCase()</li>
|
||||||
|
<li>toUpperCase()</li>
|
||||||
|
<li>charAt()</li>
|
||||||
|
</ul>
|
||||||
|
</ol>
|
||||||
|
<p>Answers:</p>
|
||||||
|
<ul>
|
||||||
|
<li>length gets the character count of a string including spaces</li>
|
||||||
|
<li>toLowerCase() turns all uppercase letters to lowercase letters</li>
|
||||||
|
<li>toUpperCase() turns all lowercase letters to uppercase letters</li>
|
||||||
|
<li>chatAt() takes a number for the index of the word to search through and returns the character at that index.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
<h2>Playground</h2>
|
<h2>Playground</h2>
|
||||||
<p>Interactive JavaScript follows</p>
|
<p>Interactive JavaScript follows</p>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
for (var i = 1; i < 10; i++) {
|
||||||
|
console.log("Ran " + i + " time(s).")
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(window.confirm("Feel prepared?")); // true or false
|
||||||
|
|
||||||
|
var question = ("50" === 50);
|
||||||
|
console.log(question);
|
||||||
|
|
||||||
|
var question2 = (true && false);
|
||||||
|
console.log(question2);
|
||||||
|
|
||||||
|
var question3 = (true || false);
|
||||||
|
console.log(question3);
|
||||||
|
|
||||||
|
// VAR price = 35.6; <-- WRONG
|
||||||
|
var price = 35.6; // <-- RIGHT
|
||||||
|
|
||||||
|
var city = "London";
|
||||||
|
|
||||||
|
if (city.toLowerCase() === "london") {
|
||||||
|
console.log("I live there too!");
|
||||||
|
} else {
|
||||||
|
console.log("I dont know where that is.")
|
||||||
|
}
|
||||||
|
|
||||||
|
var userName = window.prompt("Please enter your name:");
|
||||||
|
greetUser(userName);
|
||||||
|
|
||||||
|
var radius = window.prompt("Please enter circle radius:");
|
||||||
|
calcCirc(radius);
|
||||||
|
|
||||||
|
var testNum = window.prompt("Number to test for even:");
|
||||||
|
isEven(testNum);
|
||||||
|
|
||||||
|
function greetUser(userName) {
|
||||||
|
alert("Hello " + userName + " welcome to the page");
|
||||||
|
}
|
||||||
|
|
||||||
|
function calcCirc(radius) {
|
||||||
|
var Circ = ((2 * Math.PI) * radius).toFixed(2);
|
||||||
|
alert("Circumference is: " + Circ + " Inches.");
|
||||||
|
}
|
||||||
|
|
||||||
|
function isEven(number) {
|
||||||
|
if (number % 2 == 0) {
|
||||||
|
console.log(number + " is even");
|
||||||
|
} else {
|
||||||
|
console.log(number + " is odd");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user