In line Javascript functions not executing
Clash Royale CLAN TAG#URR8PPP
In line Javascript functions not executing
I have tried to complete the following assignment for my Javascript class (I know it's basic). But when I open the webpage none of the functions execute, what am I missing? I've tried to look on other examples but can't seem to find what I've messed up. Also any and all resources that would help with future code issues or good instructional resources is welcome as well. Any help is appreciated.
<!doctype html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WDV221 Intro Javascript</title>
<style>
div#container
width:960px;
margin:auto;
padding:10px;
background-color:white;
border:thin solid black;
</style>
<script>
var studentName = ""; //global variable to be used later
var studentEmail = ""; //global variable to be used later
function displayGreeting()
alert("Hello! Welcome to WDV221 Intro Javascript");
function getStudentName()
studentName = prompt("Please enter your name");
function getStudentEmail()
studentEmail = prompt("Please enter your e-mail address");
function printStudentInfo()
document.write("Student name:" + studentName + /n);
document.write("Student email:" + studentEmail + /n);
function displayEmail()
alert("Student Email: " + studentEmail);
function displayEmailName()
var atSymbol = 0; //local variable that will store the location of the @ symbol
//var emailNameOnly = ""; //local variable that will store the value of the name portion of the email address
studentEmail.indexOf("@");
var emailNameOnly = studentEmail.substr(0,atSymbol);
//alert( "Email name: " + studentEmail.substr(0,atSymbol) );
alert ("Email name: " + emailNameOnly);
function displayEmailServer()
var atSymbol = 0; //local variable that will store the location of the @ symbol
//var emailServerOnly = ""; //local variable that will store the value of the name portion of the email address
studentEmail.indexOf("@");
var emailServerOnly = studentEmail.substr(atSymbol + 1);
//alert( "Email name: " + studentEmail.substr(0,atSymbol) );
alert ("Email name: " + emailServerOnly);
</script>
</head>
<body>
<div id="container">
<h1>WDV221 Intro Javascript</h1>
<h2>Unit-3 Functions</h2>
<p>Tasks: </p>
<p>1. Run the displayGreeting( ) as a run time script. </p>
<script>
displayGreeting();
</script>
<p>2. Run the getStudentName( ) as a run time script.</p>
<script>
getStudentName();
</script>
<p>3. Write a function called getStudentEmail( ). The function should use the prompt( ) to ask the user to enter their DMACC Email address. Store the returned valued in the studentEmail variable that has already been defined.</p>
<p>4. Run the getStudentEmail( ) as a run time script.</p>
<script>
getStudentEmail();
</script>
<p>5. Write a function called displayEmail( ). The function will display the studentEmail variable with a message "Student Email:" in an alert. The button below will call the function when clicked.</p>
<p>
<input type="button" name="button" id="button" value="Display Email" onClick="displayEmail()">
</p>
<p>6. Complete the function called printStudentInfo( ). The function should write the studentName and studentEmail to the web page. Each in their own paragraph. </p>
<script>
printStudentInfo();
</script>
<p>7. Complete the displayEmailName( ). The function should display the name portion of the studentEmail variable. Do not include the @ symbol in the result. </p>
<p>Modify the following button to call the displayEmailName( ) with a click event handler.</p>
<p>
<input type="button" name="button2" id="button2" value="Display Email Name" onclick="displayEmailName()">
</p>
<p>8. Write a function called displayEmailServer( ). The function will display that portion of the studentEmail that follows the @ symbol. Do not include the @ symbol in the result.</p>
<p>9. Fix the button element that will run the displayEmailServer( ) with a click event handler.</p>
<p>
<input type="button" name="button3" id="button3" value="Display Email Server" onclick="displayEmailServer()">
</p>
<p> </p>
</div>
<h2> </h2>
</body>
</html>
studentEmail.indexOf("@");
atSymbol
You should have learned in class that the first debugging step is to check the console for errors.
– Barmar
1 min ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
There will be a syntax error in the console of your browser (debugging - How can I debug my JavaScript code?), and you're not storing the return value of
studentEmail.indexOf("@");
henceatSymbol
will always be zero.– Andreas
3 mins ago