fab5freddy Posted September 28, 2010 Report Posted September 28, 2010 I have recently started a Intro to JavaScript class and have become thoroughly stuck. I need to use an if statement to show if a word that the user inputs has starts with a lower or upper case letter. Here's the problem word for word from the instructor: "Write a program that asks a user to enter a single word. The program will then output several facts about the word: if the length of the word is more than 10 letters, if the word is less than the word "Algebra" or not. If the word is greater than the word "Singularity" or not, and if the word starts with an uppercase letter or a lowercase letter." The first three things I have just fine. It's the last part that I am having a hard time with. One other note I cannot use any else statements this is a lab to just get practice using "if statements" Quote
falkencreative Posted September 28, 2010 Report Posted September 28, 2010 This might get you started: <script type="text/javascript"> var str = 'i am a JavaScript hacker.'; var first = str.charAt(0); if (first == first.toUpperCase()) { document.write("First character is uppercase."); } else { document.write("First character is not uppercase."); } </script> I'm not sure how your instructor expects you to do this, and I'm not sure if this is the "right" way to do it, but this is one approach. Quote
fab5freddy Posted September 28, 2010 Author Report Posted September 28, 2010 This works great and I appreciate the help, the only thing is I need the program to run after receiving input from the user. So I prompt the user for a word. I then need to tell the user if the word entered had a upper or lowercase letter. Quote
falkencreative Posted September 28, 2010 Report Posted September 28, 2010 Sounds like you may want to use the prompt() function: http://www.tizag.com/javascriptT/javascriptprompt.php I imagine you could also do the same thing using a form and an <input> element, and using Javascript to grab the value of the field if something is entered in the field or the form is submitted. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.