Re: First *official* HTML program

Posted 01 November 2012 - 02:57 PM

fromTheSprawl, on 30 October 2012 - 10:48 PM, said:

Putting in Javascript inside HTML tag is a big no.

You mean inside the body tag? I never seem code outside html tags beside the doctype. I don't know the behavior of being outside the html tags but I believe that it's just wrong (someone correct me if not).

But if you mean inside the body tags, it's not only a yes, sometimes a big yes. You can search around the web many articles/topics/questions regarding putting the script at the bottom. Many people learned this after Yahoo published their famous guideline for speeding up pages.

But it's not just 'put at the bottom'. You have to realize that putting down makes the code loads later, if it's something essential or really necessary, you should put inside the head.

As an example, some websites, in their search box, they load the element with some text inside it, like 'type your search here'. Then when you click it the method bound to the onclick event of the element detects the click and clear up the text for me to type. Some websites this script is loaded later, so I got myself a couple of times clicking on the search box and having to manually deletes the 'type your search here' text.

IceHot, on 31 October 2012 - 11:21 PM, said:

I guess the separation of HTML files and Javascript files also grants protection against "script kiddies" finding out the logic of your code?

No. I don't know what exactly you mean by "script kiddies" but, since it's in the client, I doesn't matter from a security perspective if it is inline or loaded from a separate file.

There are two things that are affected by separating or not your js/css files: the organization of your files (obvious), and caching.

When you request page A with script X your web browser caches both. Then when you request page B with the same script X it uses the cached one.

I rarely inline my scripts and about never inline css. I only inline when it's a really minor thing.

This post has been edited by anonymouscodder: 01 November 2012 - 02:59 PM

Re: First *official* HTML program

Posted 04 November 2012 - 11:33 PM

Oh, and my while loop is STILL having trouble! It is still acting like it has no clue what the hell is going on, especially if the user types a response the program doesn't recognize (very likely, as I didn't want to predefine every one-word response the user might be thinking of!)Here is my separate Javascript code:

var yourName = prompt("What is your name?");
alert ("Hello "+yourName);
var response = "";
var responses = new Array("good", "great", "excellent", "passing", "decent", "bad", "horrible", "terrible", "failing", "ok");
var y = 0;
while (response != responses[y]) //This loop is kinda buggy; it acts as if the loop doesn't even exist!
{
response = prompt("How did I do?");
response = response.toLowerCase();
alert("response == "+response);
while (y < 9) //The purpose of doing this is to check the typed response against the array
{
y++;
} //end inner while
if ((y == 9) && (response != responses[9]))
{
alert("The only words that are permitted as input are "+ responses);
y = 0; //This is here because it is inside the while loop that executes if the user's response isn't in the array of acceptable responses
} //end if
} //end outer while
//No need to link this into a website: YOU HAVE TO GET A WEB ADDRESS! From there, you need to link this HTML into the personal website you obtained.
if ((y != 3) && (y != 7))
{
document.writeln("did "+ response); //writing your literal response to the page (if it does not contain "ing")
} //end if
else
{
document.write(" ");
for (var x = 0; x<4; x++)
{
document.write(response.charAt(x));
} //end for
document.write("ed");
} //end else
if (y<4)
{
alert("Thanks!");
} //end if
else if ((y > 4)&&(y < 9))
{
alert("Thanks for your input. I will work harder.");
} //end else
document.writeln("My name is "+yourName+" and I used this webpage!");

Either the Javascript magic fairies don't like me, or the while loop is having trouble with the dynamic array.

Re: First *official* HTML program

but thatís not a problem of the programming, thatís a problem of the design. if you donít want to ask until a match, think of another way to ask.

I was going to ask the user when their response doesn't match one of the responses in the array. When you have a while loop, the inner loop has the conditions of the outer loop, right? The most efficient way I can think of is the way I have tried to do it.

Re: First *official* HTML program

Posted 05 November 2012 - 11:38 AM

the inner while() loop is completely pointless, you could as well write y = 9;. and if you want to show the user a list of allowed answers, either show it after the first mismatch (in every case except when the user is right) or put it in the HTML from the start.

Re: First *official* HTML program

Posted 05 November 2012 - 07:22 PM

Now I am at the point where I have buttons on the page, and spots where the user can enter integer values. Then they click one of the buttons corresponding to the item whose color they want to change, and it gets changed to that value. Just wondering if the <script> calling the Javascript file corresponding to the action listeners for the buttons goes after all the buttons and text boxes. I will attach my files here. My html file uploaded successfully, but my Javascript file didn't. I post code here:

Re: First *official* HTML program

Posted 06 November 2012 - 02:16 AM

That's backwards! It also goes against programming common-sense of how to define functions! Python, C, C++, and Java all use the parenthesis at the end of their function that is being defined (at the function declaration statement). But me and the magic fairies of this land have a misunderstanding: I should have been better with my array usage. (I tried to make an array of variables. Shame on me...)

Re: First *official* HTML program

Posted 26 November 2012 - 04:51 AM

Unfortunately, the brand-new start-up company called the internship off. So now, it is time to resume learning (at normal pace). I took the suggestion to remove the "()" from the event listeners, but the page is acting as if the Javascript doesn't exist at all! (I REALLY wish I could edit past posts, as I wouldn't have to keep re-posting code as it was being changed, especially if I am modifying mistakes I exclusively report and/or catch.) Just out of curiosity, when I use this HTML code:

and the user gets to pressing one of the buttons, where is the pointer in the HTML document?

P.S.: I was thinking that I would have to call some function to attach the event listeners. Of course, the lazy way would be to include the code in sample project button 1 js file.js DIRECTLY IN THE HTML FILE, and then call the function needed, but this is kinda like using system() in C++: a no-no. Why? Because it is hard to maintain, and just as mentioned in one of the Google submissions, if the user has the Javascript disabled and tried to click the button, NOTHING HAPPENS! (This ought to be much easier than it is seeming right now.)