Cramster.com - Homework Solutions, Lecture Notes, Exams, and Free Online Homework Help
Sign Up Now! Login Help Cramster Blog
Problem Solved.
    Home    
    Homework Help    
   Answer Board   
    Resources (Beta)    
   
Member's Topic Headline:

Java Script

Know the answer? Have a better solution? Share it.
Sign Up Now for FREE!
Join the thousands of students
getting ahead in their classes.
Member Testimonials

Question:

Advertisement:

Answer | Ask New Question | Customize Profile | Leaderboards | 
FAQ

Member's Avatar

Scholar
Karma Points: 200
Respect (50%):
Date Posted: 2/6/2008 1:15:15 AM  Status: Live
Java Script
Course Textbook Chapter Problem
N/A N/A N/A N/A
Question Details:
This what is asks:
Write, test, and debug (if necessary) XHTML files that include JavaScript scripts for the following problems. When required to write functions, you must include a cript to test the function with at least two different data sets.
 
 
Input: Three numbers, using prompt ot get each.
Output: The largest of the three input numbers.
Hint: Use the predefined function Math.max.
 

Answers:

Member's Avatar

Scholar
Karma Points: 332
Date Posted: 2/6/2008 5:15:19 AM  Status: Live
Asker's Rating: Helpful   
Response:
Don't forget to rate my answer, it took 40 minutes to create the program

Answer 1.

<script language="javascript">
var firstNumber ;
var secondNumber;
var thirdNumber;
var maxNumber;
while(isNaN(firstNumber= prompt("","Please Enter FIRST number")));
while(isNaN(secondNumber= prompt("","Please Enter SECOND number")));
while(isNaN(thirdNumber= prompt("","Please Enter THIRD number")));
   
    maxNumber = Math.max(Math.max(firstNumber, secondNumber), thirdNumber);
    alert("The largest Number is : "+maxNumber);
</script>


Copy and paste the above code and save the file as "AnyName.htm" , run this file in browser.

Answer 2.

<script language="javascript">
var firstName = "";
var LastName = "";
var MiddleInitial = "";
var inputString;
var i=0;
var isLastNameSet = false;
var isfirstNameSet = false;
var isMiddleInitialSet = false;

inputString = prompt("","Please Enter your complete name e.g. Thomas Scott Jr.");
if(inputString != null)
{
    while(inputString.indexOf(" ") == -1)
        inputString = prompt("","Enter Lastname and first name seperated by space e.g. Thomas Scott");
}


while(i < inputString.length )
{
    if(inputString.indexOf(" ") == i ) isLastNameSet = true;
    if(inputString.indexOf(" ", LastName.length+2) == i ) isfirstNameSet = true;

    if(inputString.indexOf(" ") != i && !isLastNameSet)
    {
        LastName += inputString.charAt(i);
    }
    else if(inputString.indexOf(" " , LastName.length+2) != i && !isfirstNameSet)
    {
        firstName += inputString.charAt(i);
    }
    else if(inputString.indexOf(" " , LastName.length + firstName.length+2) != i && !isMiddleInitialSet)
    {
        MiddleInitial += inputString.charAt(i);
    }    
        
    i++;
}

    alert("LastName : "+ LastName + " firstName : " + firstName + " MiddleInitial : " + MiddleInitial);
</script>


Copy and paste the above code and save the file as "AnyName.htm" , run this file in browser.
JAVASCRIPT is case sensitive, so don't make any changes in the code, copy and paste as it is to make it work properly.

waf's Comment:
Thanks





By reading or posting messages on these forums, you are agreeing to the Answer Board's Terms of Service and Conduct (TSC).


About Cramster | Terms of Use | Privacy Policy | Contact Us | Press Room | Site Map | Support | Anti-Cheating Policy

Cramster.com is not affiliated with any publisher. Book covers, title and author names appear for reference only.
Copyright © 2008 Cramster, Inc.