Jump to content

This is incorrect or... Oh I don't know just take a look at it please.


L8V2L

Recommended Posts

what isn't working about it? It loops 5 times, each time overwriting x, then when the loop is done, displays the value of x from the final iteration. Are you expecting it to do something else?

 

var x="", i;
...is the same as...
var x="";var i;
...or they could have waited and declared i inside the for-loop...
for (var i=0;i<5;i++) {

 

Davejwhy do they have the '' in var x='', i; or just var='';?Thanks for explaining and refreshing my mind of that fact of var x=a, y=b, z=c; Edited by L8V2L
Link to comment
Share on other sites

because it's good practice to initialize your variables.

 

And

 

var = "";

is invalid syntax. (nor would it make sense)

Link to comment
Share on other sites

It won't work if you don't initialize x. Look at the code, test the code.

 

---

If you simply declare a variable it is given the value of undefined. This becomes a big problem if you immediately try to concatenate a string to it...

x=x + "The number is " + i + "<br>";
Link to comment
Share on other sites

Specifically, the value "" is an empty string. It is a string of text with length 0, it is a string but has no characters. If you have a variable that is eventually going to hold a string, initializing the variable to an empty string is common.

Link to comment
Share on other sites

because it's good practice to initialize your variables. And

var = "";
is invalid syntax. (nor would it make sense)

 

It won't work if you don't initialize x. Look at the code, test the code. ---If you simply declare a variable it is given the value of undefined. This becomes a big problem if you immediately try to concatenate a string to it...

x=x + "The number is " + i + "<br>";

 

Specifically, the value "" is an empty string. It is a string of text with length 0, it is a string but has no characters. If you have a variable that is eventually going to hold a string, initializing the variable to an empty string is common.

Thanks guys... justsomeguy, your explanation is more to what... I guess I could say satisfied me... I can just go with that it's necessary to do is to initializing the string a head of time with in the variable with the value... but to some instance I want to know 'WHY', not just cause that what you have to do, but why most it be done like that, why must I add the string to a variable when a variable it just use to hold information, what so important to that initialization that if I don't do it, the code it self don't work. I want to understand... I want to know JavaScript.I do appreciation all of you sharing your knowledge with me... I understand that this is what you would have done with anyone that would have ask... But it mean something more to me of which you are doing... Really, with out you, this site would only be a book with knowledge, but you are the teacher to go to when stump, I could search the web for this, but the web is both a benefit and an un-control variable of which you don't know if the information you reading are correct. I can say the same of you guys, but to see your words matching up to what I am studying are telling me your words are with truth.Codeacademy is nice but... if this site had a choice or a course of interface like codeacademy, I feel as if this site would be a lot more enjoyable... After I went through the tutorial of JavaScript two times, I found all these other resource that the tutorial did not have, your reference, and example... I could take all of this, and design a site of my own that have the component that both you, codeacademy, and htmldog are missing to truly have a site that would draw people in, not cause of the drive to learn, but cause of the enjoyment they will get from learning.But I rather improve a site that help educate me on my journey of learning... If you could are just think over it to a least hearing some of my suggestion if you want to... other wise, I'm stilling going to try to implement them using f12 interface to change the look of this site up to make it more enjoyable for me to learn, and save it as a fire to use on each page.Either way, thank you for all your help.Here something you might like to watch, very educational and insightful:
Edited by L8V2L
Link to comment
Share on other sites

Specifically, the value "" is an empty string. It is a string of text with length 0, it is a string but has no characters. If you have a variable that is eventually going to hold a string, initializing the variable to an empty string is common.

<script>function myFunction(){var x='',i; //Why this var x = '', i; and not just var x = '', i; I see that the code don't work.for (i=0;i<5;i++){x=x + "The number is " + i + "<br>";}document.getElementById("demo").innerHTML=x;}</script>I was reading that book Eloquent JavaScript, and I came across this again. Well after fiddling with it. I came to the conclusion of that cause x is going to hold the value of which the statement produce, so it need the right... How to put it... area to store it in, which in term is this '' or this "". And so that is why x is equal assign to that. Thanks for your help with it... I figure it's only right of me to report this to you. Cause I came to the realization of this due to the fact of reading the book you brought back in to my mind towards. Cause of your consideration, which cause me to reconsider reading it, is why I came to the clarity of this. In hindsight, your statement or better yet, explanation makes sense to me, to which the concept that it describe.Thanks justsomeguy, for just some guy, you are okay by me. Here's a cookie.(warm smile toward justsomeguy) COOKIE!!!!!!!!(crazy stare at justsomeguy) COOKIE!!!!!! COOKIE!!!!!!!!!! and milk...(a calm warm smile toward justsomeguy) ENJOY!!!!!(back to the crazy stare) Edited by L8V2L
Link to comment
Share on other sites

I really can't tell if you have an understanding of this. You say you understand it now, but do you? How about writing some code? How about writing an example that accepts six words from a user and then sorts the words and then prints them on the screen?

<!DOCTYPE html><html><head><meta charset="utf-8"><title>title</title><style>#output1{border:1px dotted #000;min-height:20px;width:300px;}</style><script></script></head><body><h3>Please enter six words one at a time:</h3><input type="text" id="input1"/><input type="button" id="btn1" value="Enter Word"/><h3>Here is the sorted words list:</h3><div id="output1"></div></body></html>
Link to comment
Share on other sites

I really can't tell if you have an understanding of this. You say you understand it now, but do you? How about writing some code? How about writing an example that accepts six words from a user and then sorts the words and then prints them on the screen?

<!DOCTYPE html><html><head><meta charset="utf-8"><title>title</title><style>#output1{border:1px dotted #000;min-height:20px;width:300px;}</style><script></script></head><body><h3>Please enter six words one at a time:</h3><input type="text" id="input1"/><input type="button" id="btn1" value="Enter Word"/><h3>Here is the sorted words list:</h3><div id="output1"></div></body></html>

 

function power(base, exponent){var result = 1;for(var count = 0; count < exponent; count++){result *= base;//}What's the different between putting clury braces bhind this, outputing 1024. And the one underneath?return result;//} Why do result turn 2 when curly braces includ the return result in the for stament.}show(power(2, 10));I wish I could type, I didn't have to look back, that I did it all from my head. I wish I could tpe it, that it didn't even take me long to do this simple problem... But I did, and it did... I don't care if that referancing is apart of programming, I want to be able to do it straight out my head. I know that comes with time... But that don't change the feeling of defeat. I'm writing this half way... or maybe a quater of the way through, depending on the time it take me to do it, that is.<p>How about writing some code? How about writing an example that accepts six words from a user and then sorts the words and then prints them on the screen?</p><!DOCTYPE html><html><head><meta charset="utf-8"><title>title</title><style>#output1{border:1px dotted #000;min-height:20px;width:300px;}</style><script>/*function btn1(){x=document.getElementById("input1").value;z=document.getElementById("output1");z.innerHTML=x;}<p>this what I had first, before I found the last link</p>function sortNum(a, B){return(a- B);}function btn1(x){y=document.input1.value.split(' ') I'm guessing Value is a reserved word. Try to search for it, but found only suggestion toward it. Seeing that it didn't work, I look back over the original code, and saw that value isn't a reserved word but is just referring to the value of the form, which is the inputif(x==0) //if sort alphabetically{y.sort();}else // if sort numerically{y.sort(sortNum);}document.input1.value='';for(i = 0; i < y.length -1; i++){{};}document.input1.value=document.input1.value+y+' ';document.input1.value+=y;[y.length -1] //I'm not advance enough to modify the last reference.*//*I'mma try this way again*///leaving it like this cause of the interest result it gives./*function btn1(){x=document.getElementById("input1").value.split('');x.sort();z=document.getElementById("output1");z.innerHTML=x;} *///Another copy of this to get right to preserved the on above it.function btn1(){x=document.getElementById("input1").value.split(' ');x.sort();z=document.getElementById("output1");z.innerHTML=x;}/*document.getElementById('input1').value='';document.input1.value='';for(i = 0; i < y.length -1; i++){{};}document.getElementById("input1").value=document.getElementById("input1").value+y+' ';document.getElementById("input1").value+=y;[y.length -1]*//*I can't do it, this is as close as I can get it to it.*/function btn1(){x=document.getElementById("input1").value.split(' ');x.sort();z=document.getElementById("output1");z.innerHTML=x;}/*I never said I can apply it, I just understood the concept about it being a empty string to be a place holder to put strings in.*/</script></head><body><h3>Please enter six words one at a time:</h3><input type="text" id="input1"/><input type="button" onclick="btn1()" value="Enter Word"/><h3>Here is the sorted words list:</h3><div id="output1"></div><!--<h3>Here is the sorted words list:</h3><div name="output1"><p>Why changing the number one cause the dotted line dash to disappear?</p></div><p>JavaScript is a language, and like all language. Their many ways to say one thing, but they don't deliver the same way. This deliverance to me is the most important part when programming with JavaScript. I know this isn't the way that you wanted me to do this, which I could have done it with out referring to anything else... But I'm just a nob at this point.</p>-></body></html>referance in order:www.w3Schools.comhttp://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_text_gethttp://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_sort2http://www.javascriptkit.com/javatutors/arraysort4.shtmlP.S: Those sunglasses faces are appose to be b's, I don't know what happen their.I think this: b ) must be what make that face... let's see. . B) Edited by L8V2L
Link to comment
Share on other sites

function power(base, exponent){var result = 1;for(var count = 0; count < exponent; count++){result *= base;//}What's the different between putting clury braces bhind this, outputing 1024. And the one underneath?return result;//} Why do result turn 2 when curly braces includ the return result in the for stament.}show(power(2, 10));I wish I could type, I didn't have to look back, that I did it all from my head. I wish I could tpe it, that it didn't even take me long to do this simple problem... But I did, and it did... I don't care if that referancing is apart of programming, I want to be able to do it straight out my head. I know that comes with time... But that don't change the feeling of defeat. I'm writing this half way... or maybe a quater of the way through, depending on the time it take me to do it, that is.<p>How about writing some code? How about writing an example that accepts six words from a user and then sorts the words and then prints them on the screen?</p><!DOCTYPE html><html><head><meta charset="utf-8"><title>title</title><style>#output1{border:1px dotted #000;min-height:20px;width:300px;}</style><script>/*function btn1(){x=document.getElementById("input1").value;z=document.getElementById("output1");z.innerHTML=x;}<p>this what I had first, before I found the last link</p>function sortNum(a, B){return(a- B);}function btn1(x){y=document.input1.value.split(' ') I'm guessing Value is a reserved word. Try to search for it, but found only suggestion toward it. Seeing that it didn't work, I look back over the original code, and saw that value isn't a reserved word but is just referring to the value of the form, which is the inputif(x==0) //if sort alphabetically{y.sort();}else // if sort numerically{y.sort(sortNum);}document.input1.value='';for(i = 0; i < y.length -1; i++){{};}document.input1.value=document.input1.value+y+' ';document.input1.value+=y;[y.length -1] //I'm not advance enough to modify the last reference.*//*I'mma try this way again*///leaving it like this cause of the interest result it gives./*function btn1(){x=document.getElementById("input1").value.split('');x.sort();z=document.getElementById("output1");z.innerHTML=x;} *///Another copy of this to get right to preserved the on above it.function btn1(){x=document.getElementById("input1").value.split(' ');x.sort();z=document.getElementById("output1");z.innerHTML=x;}/*document.getElementById('input1').value='';document.input1.value='';for(i = 0; i < y.length -1; i++){{};}document.getElementById("input1").value=document.getElementById("input1").value+y+' ';document.getElementById("input1").value+=y;[y.length -1]*//*I can't do it, this is as close as I can get it to it.*/function btn1(){x=document.getElementById("input1").value.split(' ');x.sort();z=document.getElementById("output1");z.innerHTML=x;}/*I never said I can apply it, I just understood the concept about it being a empty string to be a place holder to put strings in.*/</script></head><body><h3>Please enter six words one at a time:</h3><input type="text" id="input1"/><input type="button" onclick="btn1()" value="Enter Word"/><h3>Here is the sorted words list:</h3><div id="output1"></div><!--<h3>Here is the sorted words list:</h3><div name="output1"><p>Why changing the number one cause the dotted line dash to disappear?</p></div><p>JavaScript is a language, and like all language. Their many ways to say one thing, but they don't deliver the same way. This deliverance to me is the most important part when programming with JavaScript. I know this isn't the way that you wanted me to do this, which I could have done it with out referring to anything else... But I'm just a nob at this point.</p>-></body></html>referance in order:www.w3Schools.comhttp://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_text_gethttp://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_sort2http://www.javascriptkit.com/javatutors/arraysort4.shtmlP.S: Those sunglasses faces are appose to be b's, I don't know what happen their.I think this: b ) must be what make that face... let's see. b ) Yes it does.

Edited by L8V2L
Link to comment
Share on other sites

davej, I was working on another tutorial, which is why I came here for clarity on something, but then I saw your post:function power(base, exponent){var result = 1;for(var count = 0; count < exponent; count++){result *= base;//}What's the different between putting clury braces bhind this, outputing 1024. And the one underneath?return result;//} Why do result turn 2 when curly braces includ the return result in the for stament.}show(power(2, 10));

Link to comment
Share on other sites

I expect you to use the codeblocks. See those LT GT symbols on the editor bar?

<!DOCTYPE html><html><head><meta charset="utf-8"><title>showpower</title><script>window.onerror = function(m, u, l){alert('Javascript Error: '+m+'nURL: '+u+'nLine Number: '+l);return true;}</script><script>function power(base, exponent){var result = 1;for(var count = 0; count < exponent; count++){result *= base;}return result;}//end of functionwindow.onload = function(){str = '';for(var i=0 ; i<12 ; i++){str += '<b>2<sup>'+i+'</sup> = '+ power(2, i) +'</b><br/>';}document.getElementById('out1').innerHTML = str;}//end of function</script></head><body><div id="out1"></div></body></html>
Link to comment
Share on other sites

<!DOCTYPE html><html><head><meta charset="utf-8"><title>showpower</title><script>window.onerror = function(m, u, l){alert('Javascript Error: '+m+'nURL: '+u+'nLine Number: '+l);return true;}</script><script>function power(base, exponent){var result = 1;for(var count = 0; count < exponent; count++){result *= base;}return result;}//end of functionwindow.onload = function(){str = '';for(var i=0 ; i<12 ; i++){str += '<b>2<sup>'+i+'</sup> = '+ power(2, i) +'</b><br/>';}document.getElementById('out1').innerHTML = str;}//end of function<p><strong>I was right than. You using str to hold an empty string, to which you add into it, even it's self with the += which is str = str +. Like I said, I understand the concept, but putting it in use is another thing. I'm working toward getting a strong foundation of this, learning the building block, really concentrate on the beginner tutorials more than any thing, so I can understand more of it to apply it. I'm still a nob... I'm still not at such at level to compose, only read... But keep challenging me! Even know... Even know it was hard to turn in something, that even I felt I should know how to do, it's good to be challenge against a opponents that you can't beat, but don't give up trying to beat.</strong></p></script></head>

What's LT GT? I don't see it. I see open and close bracket.

Link to comment
Share on other sites

The <> button. The codeblock keeps the unexpected smiley's from being seen.
Oh, your code works, but you handle the array in a crude manner. Why do you make it look like a giant mess? I actually wanted you to enter the words one-at-a-time. That is why it says "Please enter six words one at a time:" Also it might be nice if the output was one word per line. Try adjusting your code to do things that way. Also try to use variable names that are descriptive. Not just x,y,z.
Link to comment
Share on other sites

I attempt it... I feel as if, it is to earlier for this... Especially with not guide to go by or syntax to work with... This is taking me away from my tutorial. I'm going back to them.If you really want to ask me, See to how good I have gotten to reading code instead of writing it.Give me some code to explain back to you.

Edited by L8V2L
Link to comment
Share on other sites

/*A stack is when the computer bring with it the memory of where it stop to back track into a code, and so it throw the last code from which cause it to backtrack on top of the code it self to remember that it stop there to go back, and once the code is done being read an computed, it take the memory of where it left off the top of the block of code and resume from that point. Is that correct? So print(chicken()+" came first."); is thrown on top of the function chicken as a bookmark, and ones it's done going through the function, it take the book mark off the top of the function and consume reading from that point?*/    function chicken() {  return egg();}function egg() {  return chicken();}print(chicken() + " came first.");And this too:function power(base, exponent){var result = 1;for(var count = 0; count < exponent; count++){result *= base;//}What's the different between putting clury braces bhind this, outputing 1024. And the one underneath?return result;//} Why do result turn 2 when curly braces includ the return result in the for stament.}show(power(2, 10)); 

Why would I want you to explain code that you can't write?

To get filmier with such with reading a program, I may can't call back the answer that I can't seem to remember of how to put the component together. But working on reading and recognize the code when I see it, will build a database in my memory bank to which when I sit down to write the code, it'll be easier for me to remember. If not that is okay.

Link to comment
Share on other sites

You don't seem to understand arrays or for-loops or return statements, so don't waste your time on an advanced tutorial until you review those things and understand them.

Link to comment
Share on other sites

That is beginner tutorial, I'm asking question on components of the code, not the actually code. I want to even understand the little of set.

 

Could you give me problems to solve. Like before, but with the statement code you want me to use? So I can have something to go off of.

Link to comment
Share on other sites

Some tutorials dive right into OOP which you are probably not ready for. I believe the "chicken and egg" situation you describe is something that would never happen unless you were utterly confused about what you were doing.

function power(base, exponent){var result = 1;for(var count = 0; count < exponent; count++){result *= base;//}What's the different between putting clury braces bhind this, outputing 1024. And the one underneath?return result;//} Why do result turn 2 when curly braces includ the return result in the for stament.}

 

Do you understand what a return statement does?

Link to comment
Share on other sites

From the look of it, a return is when the value is change depending on the function it proceed. What ever operation befall that value, it will be return as the answer, or and out come.

Link to comment
Share on other sites

What does this function do?

function kryptonite(){var test = 1;document.getElementById('out1').innerHTML = 'test 1';if(test==='1'){return test}document.getElementById('out1').innerHTML += 'test 2';if(test===1){return test}document.getElementById('out1').innerHTML += 'test 3';return 'dog';return 'cat';alert('Done');}
Link to comment
Share on other sites

function kryptonite(){var test = 1;document.getElementById('out1').innerHTML = 'test 1';if(test==='1'){return test}document.getElementById('out1').innerHTML += 'test 2';if(test===1){return test}document.getElementById('out1').innerHTML += 'test 3';return 'dog';return 'cat';alert('Done');}/*Comparing test to string 1, number 1... Which it return "test 1" + " test 2", which it shouldn't had for test one, and it's not even under the first if statement... unless it really did just turn in test two, but concatenated with test one by +=... less check by changing test one = with +=. OH YOU TRIED TO TRICK ME!!! .... less just check one more time by just changing the test 2 += to just a =. Yep it does. So it concatenate 'test 1' with 'test 2' ... And I'm guessing if I put the last three items in a console, it will log back 'dog' and 'cat' and alert will popup with the word 'Done'.*/
Edited by L8V2L
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...