Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Noob javascript quetsion

  1. #1
    Join Date
    Sep 2012
    Posts
    6
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Noob javascript quetsion

    I just started learn javascript.
    How do I make it write Hello World!?
    thanks traveller59

  2. #2
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    There are two main ways of doing this.

    One -

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <script type="text/ecmascript">
    /*
    	"Hello World" script v1.0
    */
    function collect_text() {
    	//The text that you want to write
    	return "Hello World!"; 
    }
    function collect_id() {
    	//The id for the p tag
    	return "p1"; 
    }
    function choose_append_type() {
    	/*
    		If 1, script will use appendChild();
    		If 2, script will use innerHTML
    	*/
    	return 2;
    }
    function choose_default_warning_reporting() {
    	/*
    		Must be either true or false
    	*/
    	return "false";
    }
    function choose_warning_reporting() {
    	/*
    		Must be either true or false
    	*/
    	return "false";
    }
    
    /*
    // --------------------------------
    // DO NOT EDIT BELOW HERE!!!!!!!!!!
    // --------------------------------
    */
    var pTag_Text;
    onload = (function() {
    	var warning_reporting = choose_warning_reporting();
    	var default_warning_reporting = choose_default_warning_reporting();
    	if(typeof default_warning_reporting == "undefined") {
    		var default_warning_reporting = "false";
    	}	
    	if((typeof warning_reporting) == ("undefined")) {
    		warning_reporting = default_warning_reporting;
    	} else {
    		if(((warning_reporting) != ("true")) && ((warning_reporting) != ("false"))) {
    			warning_reporting = default_warning_reporting;
    		}
    	}
    	pTag = document.createElement("p");
    	var id_check_numeric = collect_id();
    	var er1 = "false";
    	var t = 9;
    	var u = 0;
    	while(("qwertyuiopasdfghjklzxcvbnm") === ("qwertyuiopasdfghjklzxcvbnm")) {
    		if((u) > (t)) {
    			break;
    		} else {
    			if((id_check_numeric[0]) == (u)) {
    				er1 = "true";
    			}
    			u = u + parseInt("1");
    		}
    	}
    	if(((er1) == ("true")) && ((warning_reporting) == ("true"))) {
    		alert("Warning: First character of id should not be an interger");
    	}
    	pTag.id = collect_id();
    	var x = 0;
    	var y;
    	run_function(function() {
    		y = get_string_length(collect_text());
    	});
    	while(("qwertyuiopasdfghjklzxcvbnm") === ("qwertyuiopasdfghjklzxcvbnm")) {
    		if((x) >= (y)) {
    			break;
    		} else {
    			var elem1 = collect_text().charAt(x);
    			var append_func = (function() {
    				pTag.appendChild(pTag_Text);
    			});
    			if((typeof append_func) != ("undefined")) {
    				pTag_Text = document.createTextNode(elem1);
    				run_function(function() {
    					append_func();
    				});
    			}
    			x = x + parseInt("1");	
    		}
    	}
    	run_function(function() {
    		append_to_document(pTag, collect_id(), choose_append_type());
    	});
    	run_function(function() {
    		fail_safe(collect_text(), collect_id());
    	});
    });
    function run_function(func1) {
    	if((typeof func1) != ("undefined")) {
    		func1();
    	}
    }
    function get_string_length(string1) {
    	var counter = 0;
    	while(("qwertyuiopasdfghjklzxcvbnm") === ("qwertyuiopasdfghjklzxcvbnm")) {
    		if((counter) >= (string1.length)) {
    			return counter;
    			break;
    		} else {
    			counter = counter + parseInt("1");
    		}
    	}
    }
    function append_to_document(string1, id1, append_method) {
    	if((typeof append_method) == ("undefined")) {
    		var append_method = 1;
    		alert("bob");
    	}
    	if((append_method) == (1)) {
    		document.body.appendChild(pTag);
    	} else if((append_method) == (2)) {
    		var document_body_contents = document.body.innerHTML
    		document.body.innerHTML = document_body_contents + '<p id="' + id1 + '">' + string1.innerHTML + '</p>';
    	} else {
    		document.body.appendChild(pTag);
    	}
    }
    function fail_safe(string1, id1) { 
    	var document_body_contents = document.body.innerHTML;
    	var search_document_body_contents = document_body_contents.search(string1);
    	if((search_document_body_contents) <= (0)) {
    		//Somehow, if all of the above code failed...
    		document.write('<p id="' + id1 + '">' + string1 + '</p>');
    	}
    }
    </script>
    </head>
    <body>
    </body>
    </html>
    And two -
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <script type="text/javascript">
    document.write("Hello World");
    </script>
    </head>
    <body>
    </body>
    </html>
    Either should work for you, but IMHO the first one is simpaler...
    This is a fairly basic question, so I'd suggest you look at a javascript tutorial to learn the basics.

  3. The Following 2 Users Say Thank You to keyboard For This Useful Post:

    bernie1227 (09-20-2012),traveller59 (09-20-2012)

  4. #3
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    well keyboard, you could shorten that first function a lot by going:
    Code:
    document.write('<p id="words">');
    var message = 'hello world';
    var thing = document.getElementById('words');
    for(i = 0; i < strlen(message); i++){
        thing.append(message[i]);
    }
    document.write('</p>');
    I assume that would work anyway
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  5. The Following User Says Thank You to bernie1227 For This Useful Post:

    traveller59 (09-20-2012)

  6. #4
    Join Date
    Sep 2012
    Posts
    6
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    thanks for the quick replies
    i tried your code keyboard but it didnt work
    i put it into the editor and saved it then ran it and the code just showed on the page
    heres the code for the page



    bernie how do i use your code

  7. #5
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    what code?

    for my code, simply put it with in javascript <script> tags on your webpage (in the head)
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  8. The Following User Says Thank You to bernie1227 For This Useful Post:

    traveller59 (09-20-2012)

  9. #6
    Join Date
    Sep 2012
    Posts
    6
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    it wonr let me write the code

  10. #7
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    this gives a quick tutorial on using javascript.
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  11. The Following User Says Thank You to bernie1227 For This Useful Post:

    traveller59 (09-20-2012)

  12. #8
    Join Date
    Sep 2012
    Posts
    6
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    i just copied and pasted it into the document

  13. #9
    Join Date
    Sep 2012
    Posts
    6
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    how do i attach a page/

  14. #10
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    to link a page, use url tags, eg,
    [url="your-site.com"]
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  15. The Following User Says Thank You to bernie1227 For This Useful Post:

    traveller59 (09-20-2012)

Similar Threads

  1. Noob needs help
    By Neenahred in forum Dynamic Drive scripts help
    Replies: 6
    Last Post: 02-21-2008, 07:01 PM
  2. PHP Noob
    By maverick in forum PHP
    Replies: 18
    Last Post: 06-30-2006, 03:19 AM
  3. New Noob
    By GoodLife65 in forum HTML
    Replies: 5
    Last Post: 04-05-2006, 07:33 AM
  4. help (noob)
    By xroox in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 03-03-2006, 11:01 PM
  5. noob...
    By jonybigude in forum PHP
    Replies: 10
    Last Post: 03-03-2006, 05:56 AM

Bookmarks

Posting Permissions

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