Jump to content

Basic If statement help?


fab5freddy

Recommended Posts

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"

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...