Can I get some help with this problem? I\'m trying to print out from the functio
ID: 3544080 • Letter: C
Question
Can I get some help with this problem? I'm trying to print out from the function onto the HTML page. For some reason, it won't change the variable at the end, and won't print out the proper answer. What am I doing wrong??(BTW, the variable is supposed to equal the first initial of first and last name, with the school name).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<title>ErnestTee's Soccer School Name</title>
<script type="text/javascript">
var fName;
var lName;
var sName;
var initialFirstName = fName.charAt(0);
var initialLastName = lName.charAt(0);
var fullSchoolName = initialFirstName + initialLastName + sName;
function getSchoolName()
{ fName=prompt("First Name");
document.getElementById("firstName").innerHTML=fName;
lName=prompt("Last Name");
document.getElementById("lastName").innerHTML=lName;
sName=prompt("School Name");
document.getElementById("schoolName").innerHTML=sName;
}
</script>
</head>
<body>
<header>
<h1>ErnestTee's Soccer School Name</h1>
</header>
<p>This page will prompt ErnestTee for information and create the name of his soccer school.</p>
<p><h3>Click on the button below to enter names</h3></p>
<div id="container1">
<ul>
<li>First Name:<span id="firstName">Ernest</span></li>
<li>Last Name: <span id="lastName">Tee</span></li>
<li>School Name: <span id="schoolName">Gonzo Soccer</span></li>
</ul>
//THIS IS WHAT ISN'T WORKING*******************
<p>Username for the soccer school would be:<b> <span id="fullSchoolName">ETGonzo Soccer</span></b></p>
<p><input type="button" value="Enter names"></p>
</div>
</body>
</html>
Explanation / Answer
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<title>ErnestTee's Soccer School Name</title>
<script type="text/javascript">
function getSchoolName()
{ var fName=prompt("First Name");
document.getElementById("firstName").innerHTML=fName;
var lName=prompt("Last Name");
document.getElementById("lastName").innerHTML=lName;
sName=prompt("School Name");
document.getElementById("schoolName").innerHTML=sName;
var f = fName.charAt(0);
var l = lName.charAt(0);
var total = f+l+sName;
document.getElementById("fullSchoolName").innerHTML=total;
}
</script>
</head>
<body>
<header>
<h1>ErnestTee's Soccer School Name</h1>
</header>
<p>This page will prompt ErnestTee for information and create the name of his soccer school.</p>
<p><h3>Click on the button below to enter names</h3></p>
<div id="container1">
<ul>
<li>First Name:<span id="firstName">Ernest</span></li>
<li>Last Name: <span id="lastName">Tee</span></li>
<li>School Name: <span id="schoolName">Gonzo Soccer</span></li>
</ul>
//THIS IS WHAT ISN'T WORKING*******************
<p>Username for the soccer school would be:<b> <span id="fullSchoolName">ETGonzo Soccer</span></b></p>
<p><input type="button" value="Enter names"></p>
</div>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.