Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Non-working functions in .js file

    I've collected some of the functions I use regularly in a .js file. To make sure they worked, I made a HTML file with alert() s. But none of the alert() s work.
    I can't see whats wrong.
    Does anybody else know what may be wrong?

    Here are the files:
    The .js file
    The HTML file

    Jon
    Relax, everything is going perfectly out of control

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Edinburgh, UK
    Posts
    402
    Thanks
    2
    Thanked 1 Time in 1 Post
    Hehe this one had me bugged for a little time but I've solved the problem.

    You kept writing your conditional parts like so:

    Code:
    if (condition)
         { things to do here };
    However you should have put the ; (semi-colon) before the closing brace i.e.
    Code:
    if (condition)
         { things to do here; }
    You also put a third ; (semi-colon) in your for loop.

    Keep you html doc the same but the code below sorts out your JS file:
    Code:
    function Y2k(the_year_to_fiks){	//Y2K fiks
    	return (the_year_to_fiks < 1000) ? the_year_to_fiks + 1900 : the_year_to_fiks;
    	}
    
    //Function to determine which language the visitor uses?
    function getLanguage()
    	{
    	the_language_to_return = "";
    	if (navigator.language) //If navigator.language exist then language is whatever stored there
    		{var the_language_to_return = navigator.language;}
    
    	else if (navigator.browserLanguage) //If navigator.browserLanguage exist then language is whatever stored there
    		{var the_language_to_return = navigator.browserLanguage;}
    	
    	else if (navigator.userLanguage) //If navigator.userLanguage exist then language is whatever stored there
    		{var the_language_to_return = navigator.userLanguage;}
    
    	else if (navigator.systemLanguage) //If navigator.systemLanguage exist then language is whatever stored there
    		{var the_language_to_return = navigator.systemLanguage;}
    
    	else if (!the_language_to_return) //If none of the preceeding properties exist, language is set to
    		{var the_language_to_return = "Sorry, your browser doesn't publish any language, so you should upgrade your browser and try again.";}
    
    	return the_language_to_return; //Sends the content of language back to the variable calling it
    	}
    
    //Function to make minutes and seconds look good
    function fixTime(the_time_to_fiks)
    	{
    
    	if (the_time_to_fiks < 10)
    		{the_time_to_fiks = "0" + the_time_to_fiks;}
    
    	return the_time_to_fiks;
    
    	}
    
    //Function to set days to their real name
    function fixDay(the_day_to_fiks)
    	{
    
    	if (the_day_to_fiks == "1")
    		{the_day_to_fiks = "Mandag";}	//Enter the name for Monday between the quotes
    
    	else if (the_day_to_fiks == "2")
    		{the_date = "Tirsdag";}		//Enter the name for Tuesday between the quotes
    
    	else if (the_day_to_fiks == "3")
    		{the_day_to_fiks = "Onsdag";}	//Enter the name for Wednsday between the quotes
    
    	else if (the_day_to_fiks == "4")
    		{the_day_to_fiks = "Torsdag";}	//Enter the name for Thursday between the quotes
    
    	else if (the_day_to_fiks == "5")
    		{the_day_to_fiks = "Fredag";}	//Enter the name for Friday between the quotes
    
    	else if (the_day_to_fiks == "6")
    		{the_day_to_fiks = "Lørdag";}	//Enter the name for Saturday between the quotes
    	else 
    		{the_day_to_fiks = "Søndag";}	//Enter the name for Sunday between the quotes
    
    	return the_day_to_fiks;
    
    	}
    
    
    //Function to set months to their real name
    function fixMonth(the_month_to_fiks)
    
    {
    
    	if (the_month_to_fiks == "1")
    		{the_month_to_fiks = "Januar";}		//Enter the name for January between the quotes
    
    	else if (the_month_to_fiks == "2")
    		{the_month_to_fiks = "Februar";}	//Enter the name for February between the quotes
    
    	else if (the_month_to_fiks == "3")
    		{the_month_to_fiks = "Mars";}		//Enter the name for Mars between the quotes
    
    	else if (the_month_to_fiks == "4")
    		{the_month_to_fiks = "April";}		//Enter the name for April between the quotes
    
    	else if (the_month_to_fiks == "5")
    		{the_month_to_fiks = "Mai";}		//Enter the name for May between the quotes
    
    	else if (the_month_to_fiks == "6")
    		{the_month_to_fiks = "Juni";}		//Enter the name for June between the quotes
    
    	else if (the_month_to_fiks == "7")
    		{the_month_to_fiks = "Juli";}		//Enter the name for July between the quotes
    
    	else if (the_month_to_fiks == "8")
    		{the_month_to_fiks = "August";}		//Enter the name for August between the quotes
    
    	else if (the_month_to_fiks == "9")
    		{the_month_to_fiks = "September";}	//Enter the name for September between the quotes
    
    	else if (the_month_to_fiks == "10")
    		{the_month_to_fiks = "Oktober";}	//Enter the name for October between the quotes
    
    	else if (the_month_to_fiks == "11")
    		{the_month_to_fiks = "November";}	//Enter the name for November between the quotes
    
    	else
    		{the_month_to_fiks = "Desember";}	//Enter the name for December between the quotes
    
    	return the_month_to_fiks;
    
    	}
    
    //Browsername and version
    function findBrowser()
    
    	{
    
    	var find_the_browser_name = navigator.appName;
    	var find_the_browser_version = parseFloat(navigator.appVersion);
    
    	if ((find_the_browser_name = "Microsoft Internet Explorer") && (find_the_browser_version <= 4) && (find_the_browser_version < 7))
    		{return find_the_browser_name + " or higher";}
    	else
    		{return find_the_browser_name + " " + find_the_browser_version;}
    
    	}
    
    //Find the screen resolution of the user
    function findResolution()
    
    	{
    
    	var resolution1 = screen.width;
    	var resolution2 = screen.height;
    	var the_screen_resolution = resolution1 + "x" + resolution2;	//Gives the resolution in the format "screen width" X "screen height"
    
    	//Checks if the browser support this function
    	if ((screen.width) && (screen.height))
    		{return the_screen_resolution;}		//If it does, it returns the screen resolution
    	else
    		{return "You have a too old browser";}	//If it doesn't, the following line gives the user an error message
    
    	}
    
    //Function to ask the same question many times and store the results in an array
    function askManyQuestions(the_question_to_use, name_of_the_array, number_of_questions)
    
    	{
    //Starts the loop and sets it to continue as long as defined by the variable calling the function
    	for (var current_number_of_questions = 0; current_number_of_questions < number_of_questions; current_number_of_questions++)
    		{
    		name_of_the_array[current_number_of_questions] = prompt(the_question_to_use, "");
    		}
    
    	}
    That should sort your problems out for you
    Rich

    "An expert is a person who has made all the mistakes that can be made in a very narrow field."

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Edinburgh, UK
    Posts
    402
    Thanks
    2
    Thanked 1 Time in 1 Post
    Just wondering if you've managed to check it and see if it worked? Let me know when you know, I like to know if things have been solved or not
    Rich

    "An expert is a person who has made all the mistakes that can be made in a very narrow field."


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •