1

I'm very new to Javascript and programming all together. I've been trying to get this Javascript code to run on my website and I just can't get it to work.

var yourName = prompt("What is your name?");
if(yourName.length < 10) {
   confirm("Your name is less than 10 letters long!");
}
else {
   confirm("Your name is more than 10 letters long!");
}

I've tried saving this as a .js file and uploading it to the public_html folder with FileZilla and adding

<script src="script.js"></script>

to my index HTML file.

Can someone tell me what I'm doing wrong?

TimCodes.NET
  • 4,601
  • 1
  • 25
  • 36
Martin
  • 11
  • 1
  • 4
    Are your HTML file and JS file in the same directory? – Brennan Oct 22 '14 at 19:29
  • 2
    your browser probably has a debug console, e.g. shift-ctrl-j in firefox/chrome. Use that to see what's happening. – Marc B Oct 22 '14 at 19:30
  • Is the browser finding the file? (view-source and click on "script.js" and see if it returns the file) – Phil Oct 22 '14 at 19:30
  • do you have this code in between – GeekByDesign Oct 22 '14 at 19:31
  • What makes you think something is wrong? What does your browser's JavaScript console say? Does the browser's developer tools Net tab show the JavaScript file loading successfully? – Quentin Oct 22 '14 at 19:33
  • So I tried just putting the actual code itself between of running it from a separate file in the directory and it actually worked. However, the user has to finish the prompt before the rest of the page loads up is my only issue. – Martin Oct 22 '14 at 20:03

0 Answers0