I am having trouble debugging my JavaScript webpage. I want to make the functions run correctly when it runs through the webpage. I am getting no errors in my console so I am not sure what I did wrong?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://ift.tt/kkyg93">
<html xmlns="http://ift.tt/lH0Osb" xml:lang="en" lang="en">
<head>
<link rel="StyleSheet" href="style.css" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>CS 1301 JavaScript Lab </title>
</head>
<body>
<div align="center">
<h1> JavaScript</h1>
</div>
<div id ="function0">
<h2> letterGrade </h2>
<dl>
<dt><b>Parameters</b></dt>
<dd>grade - an integer/float representing the numerical grade</dd>
<dt><b>Return</b></dt>
<dd>a String - ‘You made a(n) [letter grade].’</dd>
<dt><b>Description</b></dt>
<dd>
This is a function, using conditionals, that determines the letter grade from the numerical grade, passed in as
a parameter. ’<br/>
</dd>
<dl>
grade: <input type="text" id="yourValue"/>
<br/>
<input type="button" value="Run Function" onClick="onClickFunc0()" />
<script>
function onClickFunc0()
{
var grade = document.getElementById('yourValue').value;
<letterGrade(grade)>
<!-- -->
}
</script>
</div>
<div id ="function1">
<h2> countLetter</h2>
<dl>
<dt><b>Parameters</b></dt>
<dd>aWord – a string representing a word</dd>
<dd>aLetter – a string representing the character to count in aWord</dd>
<dt><b>Return</b></dt>
<dd>count – integer representing the number of times aLetter appears in aWord</dd>
<dt><b>Description</b></dt>
<dd>
This is a function that takes in a word and letter as parameters. The function will then count the
number of times that the letter appears in the word, using a loop.
</dd>
<dl>
aWord: <input type="text" id="word"/>
aLetter: <input type="text" id="letter"/>
<br/>
<input type="button" value="Run Function" onClick="onClickFunc1()" />
<script>
function onClickFunc1()
{
var aWord = document.getElementById('word').value;
var aLetter = document.getElementById('letter').value;
<countLetter(aWord,aLetter)>
<!-- -->
}
</script>
</div>
<div id ="function2">
<h2> eyeForI </h2>
<dl>
<dt><b>Parameters</b></dt>
<dd>aString – any string</dd>
<dt><b>Return</b></dt>
<dd>The modified string</dd>
<dt><b>Description</b></dt>
<dd>
This is a function that takes in a string as a parameter. Replace every “I” and “i” in the string with
“eye” and return the resulting string by using a for loop.
</dd>
<dl>
aString: <input type="text" id="words"/>
<br/>
<input type="button" value="Run Function" onClick="onClickFunc2()" />
<script>
function onClickFunc2()
{
var aString = document.getElementById('words').value;
<eyeForI(aString)>
<!-- -->
}
</script>
</div>
<div id ="function3">
<h2> wordMirror </h2>
<dl>
<dt><b>Parameters</b></dt>
<dd>aString – any string</dd>
<dt><b>Return</b></dt>
<dd>The mirrored string (reversed)</dd>
<dt><b>Description</b></dt>
<dd>
This is a function that takes in a string as its only parameter. Then it returns a new string that
is the original string concatenated with the reflection of the original string (reverse the string).
</dd>
<dl>
aString: <input type="text" id="word2"/>
<br/>
<input type="button" value="Run Function" onClick="onClickFunc3()" />
<script>
function onClickFunc3()
{
var aString = document.getElementById('word2').value;
<wordMirror(aString)>
<!-- -->
}
</script>
</div>
<div id ="function4">
<h2> encryption</h2>
<dl>
<dt><b>Parameters</b></dt>
<dd>aString – a string that you want to encrypt</dd>
<dt><b>Return</b></dt>
<dd>None</dd>
<dt><b>Description</b></dt>
<dd>
This is a function that encrypts a words.
</dd>
<dl>
aString: <input type="text" id="encrypt"/>
<br/>
<input type="button" value="Run Function" onClick="onClickFunc4()" />
<script>
function onClickFunc4()
{
var aString = document.getElementById('encrypt').value;
<!-- encryption(aString) -->
<!-- -->
}
</script>
</div>
<div id ="function5">
<h2> countDown</h2>
<dl>
<dt><b>Parameters</b></dt>
<dd>startNum – an integer that is the starting number to count down from</dd>
<dd>countBy– an integer that is the number you count down by</dd>
<dt><b>Return</b></dt>
<dd>None</dd>
<dt><b>Description</b></dt>
<dd>
This is a function to count down from the first parameter (startNum) by the second parameter
(countBy). Then the function prints
the numbers from the given number to 1 (decreasing by the second
parameter each time) in descending order, with each number being printed
on its own line. </dd>
<dl>
startNum: <input type="text" id="start2"/>
countBy: <input type="text" id="increment2"/>
<br/>
<input type="button" value="Run Function" onClick="onClickFunc5()" />
<script>
function onClickFunc5()
{
var startNum = document.getElementById('start2').value;
var countBy = document.getElementById('increment2').value;
<!-- countDown(startNum, countBy) -->
<!-- -->
}
</script>
</div>
<script>
< var b = float(grade);
function letterGrade(grade) {
if (100>=b>=90) {
alert('You made a(n) A.');
} if (80 <=b <90) {
alert('You made a(n) B.');
} if (70<= b <80) {
alert('You made a(n) C.');
} if (60<= b < 70) {
alert('You made a(n) D.');
} if (0<= b < 60) {
alert('You made a(n) F.');
}
}
var count = 0;
function countLetter(aWord,aLetter){
for(var i=0; i<aWord.length; i++) {
if(aWord.charAt(i) == aLetter) {
count++;
alert(count);
}
}
}
var increment = '';
function eyeForI(aString) {
for(var i = 0; i<aString.length; i++) {
if(aString.charAt(i) == 'i' || aString.charAt(i) == 'I') {
increment= increment + "eye";
}
else {
increment = increment + aString.charAt(i);
}
}
}
var increment = '';
function wordMirror(aString) {
for(var i = aString.length; i>=0; i--) {
increment = aString.charAt(i) + increment;
alert(aString+increment)
}
}
function countDown(startNum, countBy) {
while(startNum>0) {
alert(startNum);
startNum = startNum - countBy
} {
alert('Blastoff!')
}
}
function encryption(aString){
return aString.replace(/a/g, '@').replace(/e/g, '()').replace(/h/g, '#').replace(/l/g,'1').replace(/r/g,'+').replace(/s/g.'$').replace(/v/g,'^').replace(/x/g,'*');
}
>
<!-- -->
</script>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire