Lab15
This commit is contained in:
		
							
								
								
									
										115
									
								
								Chapter ZIPs/JavaScript/ch7/ex_7_18b.html
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										115
									
								
								Chapter ZIPs/JavaScript/ch7/ex_7_18b.html
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,115 @@
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
<title>Example 7.18b</title>
 | 
			
		||||
<script type="text/javascript" src="mySource.js"></script>
 | 
			
		||||
<script>
 | 
			
		||||
function getRange()
 | 
			
		||||
{
 | 
			
		||||
 	var num1 = parseInt(prompt("Enter low end of the range"));
 | 
			
		||||
	var num2 = parseInt(prompt("Enter the high end of the range"));
 | 
			
		||||
	var num3 = parseInt(prompt("Enter the number to check"));
 | 
			
		||||
	var answer = checkRange(num3, num1, num2);
 | 
			
		||||
	document.getElementById("line1").innerHTML = ("low end: " + num1 + "<br />");
 | 
			
		||||
	document.getElementById("line2").innerHTML = ("high end: " + num2 + "<br />");
 | 
			
		||||
	document.getElementById("line3").innerHTML = ("number to be checked: " + num3 + "<br />");
 | 
			
		||||
	if (answer)
 | 
			
		||||
		document.getElementById("line4").innerHTML = ("Number is in range");
 | 
			
		||||
	else
 | 
			
		||||
		document.getElementById("line4").innerHTML = ("Number is NOT in range");
 | 
			
		||||
}
 | 
			
		||||
function getPercent()
 | 
			
		||||
{
 | 
			
		||||
 	var num1 = parseInt(prompt("Enter the initial value"));
 | 
			
		||||
	var num2 = parseInt(prompt("Enter the percentage discounted"));
 | 
			
		||||
	var newVal = prompt("Enter 'new' to get the value of " + num1 + " after " + num2 + "% is taken off or enter 'reduction' to see the amount of " + num1 + " multiplied by " + num2 + "%");
 | 
			
		||||
	if (newVal == "new")
 | 
			
		||||
		var choice = "y";
 | 
			
		||||
	else choice = "n";
 | 
			
		||||
	var result = checkPercent(num1, num2, choice);
 | 
			
		||||
	document.getElementById("line9").innerHTML = ("Initial value: " + num1 + "<br />");
 | 
			
		||||
	document.getElementById("line10").innerHTML = ("Percentage taken: " + num2 + "%<br />");
 | 
			
		||||
	document.getElementById("line11").innerHTML = ("Result is: " + result);
 | 
			
		||||
}
 | 
			
		||||
function getChar()
 | 
			
		||||
{
 | 
			
		||||
 	var theWord = prompt("Enter the word");
 | 
			
		||||
	var letter = prompt("Enter the letter you are interested in");
 | 
			
		||||
	var spot = parseInt(prompt("Enter the place you want to find this character"));
 | 
			
		||||
	var answer = charAtPlace(theWord, spot, letter);
 | 
			
		||||
	document.getElementById("line5").innerHTML = ("Your word: " + theWord + "<br />");
 | 
			
		||||
	document.getElementById("line6").innerHTML = ("The letter: " + letter + "<br />");
 | 
			
		||||
	document.getElementById("line7").innerHTML = ("The spot where you hope to find this letter: " + spot + "<br />");
 | 
			
		||||
	if (answer)
 | 
			
		||||
		document.getElementById("line8").innerHTML = ("The letter, " + letter + " is at character number " + spot + " in " + theWord);
 | 
			
		||||
	else
 | 
			
		||||
		document.getElementById("line8").innerHTML = ("The letter, " + letter + " is NOT at character number " + spot + " in " + theWord);
 | 
			
		||||
}
 | 
			
		||||
function checkIt()
 | 
			
		||||
{
 | 
			
		||||
 	var theWord = prompt("Enter the word");
 | 
			
		||||
	var letter = prompt("Enter the letter you are interested in");
 | 
			
		||||
	var answer = checkForChar(theWord, letter);
 | 
			
		||||
	document.getElementById("line13").innerHTML = ("Your word: " + theWord + "<br />");
 | 
			
		||||
	document.getElementById("line14").innerHTML = ("The letter: " + letter + "<br />");
 | 
			
		||||
	if (answer)
 | 
			
		||||
		document.getElementById("line15").innerHTML = ("The letter, " + letter + " is found in " + theWord);
 | 
			
		||||
	else
 | 
			
		||||
		document.getElementById("line15").innerHTML = ("The letter, " + letter + " is NOT found in " + theWord);
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
<style type="text/css">
 | 
			
		||||
<!--
 | 
			
		||||
body {
 | 
			
		||||
	margin: 10%;
 | 
			
		||||
}
 | 
			
		||||
-->
 | 
			
		||||
</style>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<div style="width: 700px; margin-left: auto; margin-right: auto;">
 | 
			
		||||
	<div style = "width: 300px; float: left;">
 | 
			
		||||
		<h2>Get Range Function</h2>
 | 
			
		||||
		<h3>Click to check a range</h3>
 | 
			
		||||
		<p><input type="button" id="range" value="Enter a range" onclick="getRange();" /></p>
 | 
			
		||||
		<div id = "line1">  </div>
 | 
			
		||||
		<div id = "line2">  </div>
 | 
			
		||||
		<div id = "line3">  </div>
 | 
			
		||||
		<div id = "line4">  </div>
 | 
			
		||||
	</div>
 | 
			
		||||
	<div style = "width: 300px; float: right;">
 | 
			
		||||
		<h2>Get Percent Function</h2>
 | 
			
		||||
		<h3>Click to get a percent of a number</h3>
 | 
			
		||||
		<p><input type="button" id="percent" value="Enter a number" onclick="getPercent();" /></p>
 | 
			
		||||
		<div id = "line9">  </div>
 | 
			
		||||
		<div id = "line10">  </div>
 | 
			
		||||
		<div id = "line11">  </div>
 | 
			
		||||
		<div id = "line12">  </div>
 | 
			
		||||
	</div>
 | 
			
		||||
	<div style="clear:both;"></div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<div style="clear:both;"></div>
 | 
			
		||||
 | 
			
		||||
<div style="width: 700px; margin-left: auto; margin-right: auto;">
 | 
			
		||||
	<div style = "width: 300px; float: left;">
 | 
			
		||||
		<h2>Get One Character Check Function</h2>
 | 
			
		||||
		<h3>Click to check if a character is in a spot in a string</h3>
 | 
			
		||||
		<p><input type="button" id="character" value="Enter string" onclick="getChar();" /></p>
 | 
			
		||||
		<div id = "line5">  </div>
 | 
			
		||||
		<div id = "line6">  </div>
 | 
			
		||||
		<div id = "line7">  </div>
 | 
			
		||||
		<div id = "line8">  </div>
 | 
			
		||||
	</div>
 | 
			
		||||
	<div style = "width: 300px; float: right;">
 | 
			
		||||
		<h2>Get Another Character Check Function</h2>
 | 
			
		||||
		<h3>Click to check if a character is in a string</h3>
 | 
			
		||||
		<p><input type="button" id="character" value="Enter string" onclick="checkIt();" /></p>
 | 
			
		||||
		<div id = "line13">  </div>
 | 
			
		||||
		<div id = "line14">  </div>
 | 
			
		||||
		<div id = "line15">  </div>
 | 
			
		||||
	</div>
 | 
			
		||||
	<div style="clear:both;"></div>
 | 
			
		||||
</div>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user