Graduate Assignment 2 Redo
Because the parameters where not spelled out until a couple days ago I am redoing the entire project.
by Larry Adams
HTML
<h1>JavaScript Display Possibilities</h1>
<h2>Displaying data in different ways:</h2>
<ol>
<li>Writing into an alert box, using window.alert().</li><br>
<li>Writing into the HTML output using document.write().</li><br>
<li>Writing into an HTML element, using innerHTML.</li><br>
<li>Writing into the browser console, using console.log().</li><br>
</ol>
<p>w3school has an excellent examples of the 4 client side JavaScript output</p>
<p>See examples at <a href="http://www.w3schools.com/js/js_output.asp" target="_blank">w3Schools</a></p>
<br>
<h3>Your Task</h3>
<p>Your Task is to write 4 examples by using a conditional statement returning true/false, an array, an object, and a function. </p>
<h3>Example 1</h3>
<p id="demo"></p>
<br>
<hr>
<br>
<h3>Example 2</h3>
<h3 id="text">Change My Text!</h3>
<input type="text" id="myTextField"/>
<input type="submit" id="myBtn" value="Change Text" onclick="changeText()"/>
<br>
<hr>
<br>
<h3>Example 3</h3>
<p id="jHarvard"></p>
JavaScript
// Example of a popup window, function, conditional statement, and innerHTML output
// Example 1
var person = prompt("Please enter your name");
if (person != null) {
document.getElementById("demo").innerHTML =
"Mr. " + person + " welcome to Harvard University!";
}
// Example 2
function changeText(){
var newText = document.getElementById('myTextField').value;
if( newText.length==0 ){
alert('Change this text please!.');
return;
}
var text = document.getElementById('text');
text.innerHTML = newText;
}
// Example 3 An Array, Object, and Console.log
var person = {firstName:"John", lastName:"Harvard", Born: "1607"};
console.log(person);
document.getElementById("jHarvard").innerHTML = person["firstName"];