Jump to content

nhuyvan1106

Members
  • Posts

    17
  • Joined

  • Last visited

Posts posted by nhuyvan1106

  1. Hi yo, same here, I just didn't discover the deep PASSION for programming after I got fired from Amazon( :facepalm: , I am really glad that happened even though I was really depressed, if it had not, it would have followed the auto mechanic path which would be very different), but anyway, I had the same questions as you do also, and I am just 23 like you are too :D, I started out with HTML, CSS, then JS, but that is not enough though, I am now teaching myself java (and android programming) which is really frustrating to learn yourself, but like I said, PASSION, it helps me overcome my frustration(I even hit my head many times for being so stupid :D), anyway, let me tell you, web developers, software developers, etc... are the most well-paid technology-related jobs ever(You can google). To develop websites, HTML, CSS, and JS are the must-learns, besides that, you should learn some server-side programming language, for example Java which is what I am learning right now, you can choose other languages as well, but Java is really great when you learn it, many people hate it, and call it verbose(but hey, people always have something to hate on) but I think Java is a bit easier to learn than C++, trust me, when you look at C++'s data types(which is the first thing you'll learn for every language), you'll hate it, it is just redundant, because C++ is platform-dependent, I do hate it ALOT, and Java is platform-independent(Probably the only one that is as far as I know) and many other features especially those APIs or class libraries(which are code written by other people you can use, people at SunMicrosystem often say "We do this, so you don't have RE-INVENT THE WHEEL"), there's a saying about Java "Write once, run anywhere", but what I said doesn't make learning Java a piece of cake, there's alot to it just like other languages, anyway, you need to know server-side programming also to create sophisticated, beautiful applications that can do stuff for a website, JS is mostly for client-side programming, I just want to give one advice, very good one, when you become frustrated and want to quit(which I have never thought of even), it is never easy when you learn something on your own, so think about the day that you have become successful with what you learn, making a very good living doing it, it will keep you motivated ALOT, and that is what I am doing to motivate myself, and it just excites me every time, and one final word, thank you Amazon for firing me haha. Sorry for the long response.

  2. Oh yeah, mannnnnnnnnn, that makes alot of sense, because setInterval() doesn't cancel itself out like setTimeout() does, so it will keep calling itself multiple times during 1-second interval really lightning-fast, that is why the number appears to be skipping over, man, thanks alot for saving me a headache. :good:

  3. <!DOCTYPE hmtl><html lang = "en-US">    <head>	<meta charset = "UTF-8">	<script type = "text/javascript">	    window.onload = myFunction;            var i = 11;	    function myFunction() {		document.getElementById("output").innerHTML = display();		setTimeout(myFunction, 1000);	    }				    function display() {		 i--;		 var prompting;		 if (i == 0) {		    i = 10;		    prompting = confirm("Do you want to go?");		    if (prompting == true) {			window.location = "http://www.google.com";		    }		 }		 return "You will be re-directed in " + i;	    }			        </script>	</head>		<body>	    <div id = "output"></div>	</body></html>

    Hi guys, I just made this little countdown clock, but one thing is really confusing me, the setTimeout() function up there, it works fine, but whenever I replace it with setInterval(), the variable i doesn't step down by every 1 unit at all, instead, it goes like, 9 ....7....3, but when I use setTimeout(), it goes 10..9..8.. till 0. You guys know why? Thank you very much.

  4. <!DOCTYPE html><html lang = "en-US">    <head>	<meta charset = "UTF-8">	<style type = "text/css">            fieldset {		width: 850px;		margin: auto;		text-align: center;		}		#txtField {		    text-align: center;		}		#tryAgainBtn {		    display: none;		}	 </style>			 <script type = "text/javascript">	     window.onload = myFunction;	     var randomNumber;	     var outPut;	     function myFunction() {	         randomNumber = Math.floor(Math.random()*1000);		 document.getElementById("checkBtn").onclick = checkAnswer;		 document.getElementById("tryAgainBtn").onclick = tryAgain;	     }				     function checkAnswer() {	         outPut = document.getElementById("outPut");		 outPut.innerHTML = "";						 var myInput = document.getElementById("txtField");					    	 if (myInput.value < 0 || myInput.value > 1000) {		 return outPut.innerHTML += "I said between 0 and 1000.";		 }		 if (myInput.value == "") {		 return outPut.innerHTML += "Please enter a number between 0 and 1000!!!";		 }		 if (myInput.value > randomNumber) {		 outPut.innerHTML += "Too High !!!";		 }		 if (myInput.value < randomNumber) {		 outPut.innerHTML += "Too low !!!";		 }		 if (myInput.value == randomNumber) {	         outPut.innerHTML += "Yay, you are awesome !!!";		 document.getElementById("tryAgainBtn").style.display = "inline";		 }		 document.getElementById("txtField").onclick = reset();		 }					 function tryAgain() {	             document.getElementById("txtField").value = "";		     outPut.innerHTML = "";		     document.getElementById("tryAgainBtn").style.display = "none";		     randomNumber = Math.floor(Math.random()*1000);		}	</script>    </head>	    [attachment=1390:MyGame.png]<body>	    <form action = " " id = "myForm">		    <fieldset>			    <p>Let's play a guessing game, I am thinking about a number				   between 0 and 1000. Enter your guess in the box, I'll tell				   you if it's correct or not.				</p>								<div id = "outPut">				</div>							    <input type = "text" id = "txtField"/> <br/>								<button type = "button" id = "checkBtn">				    Check your guess!!!				</button> <br/>				<button type = "button" id = "tryAgainBtn">				    Try again ???				</button>			</fieldset>		</form>	</body></html>

    Hi guys, I am building this text-based guessing game(please don't judge, I'm just a starter), everything is working correctly, just one thing I can't find the answer anywhere at all, but I sure know you guys do know the answer, my question is, btw, I've attached a picture so you can conjure up what I am trying to say, ok, so, after the user entered a value, and they are gonna enter another value, so when the user clicks on the box, what do I do to make the previously entered value removed, like when they click on the box, the previous value disappears, I've tried using the reset() method as you can see in the code, but every time the "Check your answer" button is clicked, the value disappears right away, and that is not I want, I really don't know method to use? any suggestions are greatly appreciated. Thank you very much for your time and help.

    post-173058-0-44452900-1401600043_thumb.png

  5. <html><head><script type="text/javascript">  function showPosition()  {    var oElement = document.all.oCell;    var myDiv = document.all.myDiv;        alert("The span element is at (" + oElement.offsetLeft +           "," + oElement.offsetTop + ")n" + "The offset parent is "           + oElement.offsetParent.tagName + " offsetHeight is " + oElement.clientHeight);  }  </script></head><body onload="showPosition()"><div id = "myDiv" style = "width: 100px; padding: 10px 20px; position: relative; border: 1px solid black;float: right;">					<span id="oCell">This is a small table.</span>	</div></body></html>

    Hi guys, I was messing around with the offsetSomething and clientHeight properties(experimenting with them actually), I noticed that clientHeight always returned "0" on that span element, when I changed to offsetHeight, it returned a value other than "0", BUT when set "style = 'display:block' " on that <span> element, clientHeight returned some value other than "0", and everytime I removed "style = 'display: block;' ", clientHeight returned "0", so clientHeight property only works on block-level elements or am I doing something wrong here? Thank you in advance guys.

  6. Hi guys, I just have a dumb question but looks like I can't find the answer anywhere at all. What is a global function? specifically, how do I determine the scope of a function? I know the definition of the variable scope, but function scope, I don't, hope you guys could clarify this for me.

     

    One more thing. I have this code down below about the "this" keyword. Doesn't the "this" keyword refer to the element that triggers the event? if so, why it pops up "undefined" when I click on the paragraph? I'm pretty positive "this" in my case is bound to a global variable(that's why it gives me an "undefined" id) which is the window object, but I don't understand why "this" is not referring to the "<p>" element at all. Any tips and hints are greatly appreciated brothers(Please take it easy on me if I sound dumb, I just started teaching myself JS a couple weeks ago or so, so)

     

    Thank you very much guys.

    <!DOCTYPE html><html><head><script>function myFunction(){ alert(this.id);}</script></head><body><p id = "myPa" onclick="myFunction()">This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph.</p></body></html>
  7. <!DOCTYPE html><html><head><title>tab</title><script>function myFunction(e){ alert(e.target.id);}</script></head><body onclick="myFunction(event)"><p id="myPara1">Click on a paragraph. An alert box will alert the element that triggered the event.</p><p id="myPara2">Click on a paragraph. An alert box will alert the element that triggered the event.</p><p id="myPara3"><strong>Note:</strong> The target property returns the element that triggered the event, and not necessarily the eventlistener's element.</p></body></html>

    Man, I am so slow at this for some reason(probably I am too stupid), why does it make a difference after you added the "event" parameter?

  8. <!DOCTYPE html><html><head><script>function myFunction(e){ alert(e.target.id);}</script></head><body><p  id = "myBody" onclick="myFunction()">Click on a paragraph. An alert box will alert the element that triggered the event.</p><p><strong>Note:</strong> The target property returns the element that triggered the event, and not necessarily the eventlistener's element.</p></body></html>

    I attempted to do this as you can see, but the handler won't do anything, what am I still missing here guys? Thank you

  9.  

    In JavaScript it is merely a good practice to get used to. It improves readability of your code when others come back to look at it. JavaScript is mostly type-insensitive and also automatically makes sure that new variables made are truly empty if never initialized. There is no direct type classification when making a variable and JavaScript merely assumes the type by what is currently entered in it, casting (changing) the data to other datatypes when needed.

     

    In other languages, like C, the language will assign some random available address to the variable and immediately use whatever is already in that address (usually just garbage data). You're required to determine the datatype at creation so that the language knows how many bits the variable needs to use. If you forget to initialize variables in those languages your code could run away with non-sensible info making it do bad things.

     

    So if you plan to write in multiple languages always initializing is simply a good habit to get into, unless you have some special use case in explicitly NOT initializing.

    Thanks alot bro

  10. <!DOCTYPE html><html><head><script>function myFunction(e){ alert(e.target);}</script></head><body onclick="myFunction(event)"><p>Click on a paragraph. An alert box will alert the element that triggered the event.</p><p><strong>Note:</strong> The target property returns the element that triggered the event, and not necessarily the eventlistener's element.</p></body></html>

    Hi guys, I am really struggling with this right now, please help. As you can see the above, I don't really understand these lines of code <body onclick="myFunction(event)">, and

    function myFunction(e)

    {alert(e.target);}

     

    what do "event" and "e" do, I know they are parameters which I can use whatever I like, my question is, why do I need "event" and "e" parameters here, and why are they so important?

     

    Second question, this line <body onclick="myFunction(event)">, I don't really know what the difference between <body onclick="myFunction(event)"> and <body onclick = myFunction>(without parenthesis and quotes). Thanks a bunch guys.

  11.     function getPassword(){      var correct = "HTML5";      var guess = "";      while (guess != correct){        guess = prompt("Password?");      } // end while      alert("You may proceed");    } 

    Hey guys, I am a newbie, here, so it would be much appreciated if you guys could clarify this issue for me. As you can see the above javascript function (asking the user to enter the correct password after they click on the button or the loop will continue forever), my question is that, why do we need to set the "guess" variable's value to empty in this case, why don't we just leave it as undefined(var guess;), I've seen other people's codes like that as well, they always set the initialization variable's value to empty. The second question is, why do we have "guess = prompt('Password?')", is it okay if I just write "prompt = ('Password?')". Please help me guys, any suggestions are greatly appreciated. God bless you.

×
×
  • Create New...