I'm pretty new to coding, and I'm trying to complete Codecademy's Javascript course. I've learned a little bit about HTML/CSS and I'm almost done with JavaScript. I've researched people having similar problems, but those solutions typically involve JQuery, which I haven't learned.
Here is my HTML (index.html):
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="main.js"></script>
</head>
<body>
</body>
</html>
Here is the beginning of my JavaScript:
alert();
// Acquire character's name and check to make sure it's a string
var charName = prompt("NASA Receptionist: 'Welcome to Mission Control.
May I have your last name, please?'");
var nameCheck = function(charName) {
while (typeof charName === "number") {
charName = prompt("NASA Receptionist: 'Surely, your name is not
a number... Please, may I have your last name?'");
}
};
nameCheck(charName);
NOTE: index.html is in the same folder as main.js
When I open the index.html, nothing happens, not even the opening alert(). Am I missing something?
You have error in your script as you cannot make javascript statements in multiple lines without using escaping slash .
I was getting this error :
SyntaxError: unterminated string literal
var charName = prompt("NASA Receptionist: 'Welcome to Mission Control.
Here is the modified code :
alert();
// Acquire character's name and check to make sure it's a string
//The \r\n\ will format the string in prompt and make it appear in new line
var charName = prompt("NASA Receptionist: 'Welcome to Mission Control. \
\r\n\May I have your last name, please?'");
var nameCheck = function(charName) {
while (typeof charName === "number") {
charName = prompt("NASA Receptionist: 'Surely, your name is not \
\r\n\a number... Please, may I have your last name?'");
}
};
nameCheck(charName);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With