Jump to content

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


L8V2L
 Share

Recommended Posts

first off... You need a help section(if you have one already, my apologies) I know this is the help section, but I feel as if these is more as a moderator section to give information on things that could be helpful to look at... That don't really make sense, but in away it do. Even know you do have "pinned" to notify...<!DOCTYPE html><html><body><p id="p1">Click the button to locate where "locate" first occurs.</p><p id="p2">0</p><button onclick="myFunction()">Try it</button><script>function myFunction(){var str=document.getElementById("p1").innerHTML;var n=str.indexOf("hi");document.getElementById("p2").innerHTML=n+1;}</script></body></html><!--Finding a String in a StringThe indexOf() method returns the position (as a number) of the first found occurrence of a specified text inside a string:Examplevar str="Hello world, welcome to the universe.";var n=str.indexOf("welcome");Try it yourself »The method returns -1 if the specified text is not found.it doesn't return -1-->

Link to comment
Share on other sites

what is your question?

it doesn't return -1!!!!!!!!!...... LOL! 4.13==pie; result NOT4.13=="4.13"; result TRUE4.13!="4.13"; result FALSE4.13===4.13; result TRUE4.13!==4.13; result FALSEPIE PIE PIE PIE 4.13!!!!
Link to comment
Share on other sites

The code looks OK.

Cold you explain this i = i + 1;i += 1;i++;++i;to me? ++i and i++.I didn't want to start a new topic for this, it made me felt like I would be spanning... I feel you should really have a section for question... Even know this is that section.
Link to comment
Share on other sites

First of all the code you posted does return -1. You then add 1 to it and so it displays 0.

 

These are the same:

i = i + 1;

i += 1;

i++;

 

The statement j = i++ means set j = i and then increment i by 1.

 

The statement j = ++i means increment i by 1 and then set j = i.

Link to comment
Share on other sites

First of all the code you posted does return -1. You then add 1 to it and so it displays 0. These are the same:i = i + 1;i += 1;i++; The statement j = i++ means set j = i and then increment i by 1. The statement j = ++i means increment i by 1 and then set j = i.

I know in in complex equation it's different.How does it different it?Does i++ increment j after it is run through the program or just after it is assign to j?++i add i to 1 than assign j to 1 or vice versa (knowing that variable are property and property are variable depending on what side of the = sign it is on at the time).... lol you know saying property are variable and variable are property speak true of the saying you are what you take in to be.(reedited for more understanding of what I'm asking)Such as this:<!DOCTYPE html><html><body><script>cars=["BMW","Volvo","Saab","Ford"];for (var i=0;i<cars.length;i++){document.write(cars + "<br>");}</script></body></html>Even know change this:<script>cars=["BMW","Volvo","Saab","Ford"];for (var i=0;i<cars.length;i++){document.write(cars + "<br>");}</script>To this:<script>cars=["BMW","Volvo","Saab","Ford"];for (var i=0;i<cars.length;++i){document.write(cars + "<br>");}</script>Change nothing(not entirely true mind you) about how the data is input and than out put to display.What is it saying?Neo! What is the matrix saying?! I got to know! Edited by L8V2L
Link to comment
Share on other sites

What's your question?Indeed.Problem solved.[/quote<!DOCTYPE html><html><body><script>cars=["BMW","Volvo","Saab","Ford"];var i=2,len=cars.length;for (; i<len; i++){document.write(cars + "<br>");}</script></body></html>var i = 9;for(; ;){if(i === 0)break;console.log(i);i--;Can you explain for( ;) and for(; ;) in both these code to me?

Link to comment
Share on other sites

 

for( initialization ; test ; increment ){}for(var i=0, len=myarray.length ; i<len ; i =i+3){alert('i = '+ i);}
The only way to learn this stuff is to play with it.

 

True. Thank you. Truthfully that what I been doing... I'm in the process of going back through the JavaScript tutorial. I'm going to gain a strong foundation of JavaScript before I have more. I went through it ones along with jQuery, and through a few of other tutorial.Are you a programmer? I mean as in a career? Edited by L8V2L
Link to comment
Share on other sites

In the examples in post 9, it does not matter whether you use i++ or ++i. It only matters if you're using the value of that expression directly in another expression, e.g.:el.id = "text" + (i++);is different thanel.id = "text" + (++i);

Link to comment
Share on other sites

No one touch this!!! ... as if anyone watching this question. I'm saving this for later... if I ever come back to it.<!DOCTYPE html><html><head><script>/*function setCookie(cname,cvalue,exdays){var d = new Date();d.setTime(d.getTime()+(exdays*24*60*60*1000));var expires = "expires="+d.toGMTString();document.cookie = cname+"="+cvalue+"; "+expires;}function getCookie(cname){var name = cname + "=";var ca = document.cookie.split(';');for(var i=0; i<ca.length; i++){var c = ca.trim();if (c.indexOf(name)==0) return c.substring(name.length,c.length);}return "";}function checkCookie(){var user=getCookie("username");if (user!=""){alert("Welcome again " + user);}else{user = prompt("Please enter your name:","");if (user!="" && user!=null){setCookie("username",user,30);}}}*/</script><script>function setCookie(cname,cvalue,exdays){var d=new Date();d.setTime(d.getTime()+(exdays*24*60*60*1000));var expires = "expires"+d.toGMTString();document.cookie"="cname+cvalue+"; "+expires;}function getCookie(cname){var name=cname+"=";var ca=document.cookie.split(';');for(var i=0; i<ca.length; i++){var c=ca.trim();if (c.indexof(name)==0) return c.substring(name.length,c.length);}return "";}function checkCookie(){var user= getCookie("user name");if(user!=""){alert("Welcome again "+ user);}else{user=prompt("please enter your name:","");if(user!="" $$ user!=null){setCooke("username",user,30);}}}</script></head><body onload="checkCookie()"></body></html>

Edited by L8V2L
Link to comment
Share on other sites

it doesn't return -1!!!!!!!!!

 

why would you expect this code to return -1?

var str="Hello world, welcome to the universe.";var n=str.indexOf("welcome");

welcome is in "Hello world, welcome to the universe."

Link to comment
Share on other sites

why would you expect this code to return -1?

var str="Hello world, welcome to the universe.";var n=str.indexOf("welcome");
welcome is in "Hello world, welcome to the universe."

 

Cause it said it would, I'll find the tutorial which I'm referring to later.
Link to comment
Share on other sites

Cause it said it would, I'll find the tutorial which I'm referring to later.

really? that's not what the tutorial says though (it says it returns 13, which is correct)

http://www.w3schools.com/jsref/jsref_indexof.asp

 

% (Modulus) 14 % 9 // returns 5 <--------> Explain please.

the modulus operator returns the remainder from a division expression.

http://www.w3schools.com/js/js_operators.asp

 

In this case the remainder from dividing 14 by 9 is 5. (9 goes into 14 once, with a remainder of 5)

  • Like 1
Link to comment
Share on other sites

Thanks for replying to my question... I can't say I understand. With the link you supply me with it give an explain of 5%2=1, as well as 5/2=2.5... to me it look as if it's rounding off... I been studying today so about to take a little break... which is never a break, just off the course to keep my inspiration up to keep going.Thanks again for the reply!

Link to comment
Share on other sites

I read the top, and even went into the link of quotient value... Thank like mister cat(that you)said. I played with it... You or wiki couldn't just tell me it's minus the remainder... Jump in the corner looking at you all foaming at my mouth. "GET YOUR DAM HANDS OFF ME YOU DAM DIRTY APES, ALL OF YOU! YOU'RE NUTS YOU HEAR, YOUR NUTS, YOUR HERE!"All number have a pattern, so (I look back to the name I was referring to(I forgot it)Than I saw this "Modulus (division remainder)" Note the remainder... With that said, I'm back in the corner growling at you all.) with the modulus, it's more of the... remainder... (back in the corner "YOU ALL! DAM YOU ALL, YOU DAM DIRTY APES, ALL OF YOU.") THAT REMIND ME! STILL DIDN'T FINISH THAT MOVIE, The Rise Of Planet of The Ape...Is anyone on this site a wizard by any chance... I know no one is a cardboard hole punching wizard... That's more a mad wizard to me. Just a high rank wizard... If you don't know what I mean, than never mind. Thanks for helping and everything.
Link to comment
Share on other sites

are-you-wizard.jpg

<!DOCTYPE html><html><body><p>Click the button to loop through a block of code five times.</p><button onclick="myFunction()">Try it</button><p id="demo"></p><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></body></html>
Link to comment
Share on other sites

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?

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
 Share

×
×
  • Create New...