[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

https://studio.code.org/projects/ap plab/rCSaLWcbAWUZ9KTxITE

The stories and information posted here are artistic works of fiction and falsehood.
Only a fool would take anything posted here as fact.

Thread replies: 18
Thread images: 3

File: download.jpg (7KB, 300x168px) Image search: [Google]
download.jpg
7KB, 300x168px
https://studio.code.org/projects/applab/rCSaLWcbAWUZ9KTxITEuMQ

noobfag here please help me I dont know how to get the out of bounds in arrays fixed
>>
>>724087088
Let me take a quick look, anon. Unless you mean you don't know what that error means?
>>
barely looked at the code and idk the language but 99% calling it right now you're asking for an index just outside the length of the array.

When you retrieve items from an array, the first cell is 0, so an array of length n has final array number n-1. You want to loop from 0 to length - 1
>>
>>724087088
dude, your next and back callback functions have no code checking if your index has gone out of range.
>>
>>724087088
>>724087381
I can't alter your code to debug it myself, but my suggestion would be to change a couple of lines slightly:

Line 1: var current = 1;
Line 3 & 7, change current+1 to just current.

And in your NxtBtn and lastBtn events, put everything into if blocks:

onEvent("NxtBtn", "click", function(event)
{
if(current+1 < favoriteList.length)
{
current = current+1;
newText();
}
});
onEvent("lastBtn", "click", function(event)
{
if(current-1 >= 0)
{
current = current-1;
newText();
}
});
>>
>>724088486
Oh, and I missed a line.

Line 4, current-1. Or, you could just specify 0, meaning the first index in the array, since that's what you were aiming for anyway.
>>
>>724088486
alright trying to fix it now
>>
>>724089371
Your code worked but i didn't specify that if i were to reach the last array and i were to hit next it should go back to the first list.
>>
>>724089627
Awesome, good luck anon!
>>
File: 123213.png (413KB, 1920x1080px) Image search: [Google]
123213.png
413KB, 1920x1080px
>>724090177
>>724089371
>>
>>724090163
>>724090366
>i didn't specify that if i were to reach the last array and i were to hit next it should go back to the first list.
Okay, that's easy to do as well.

onEvent("NxtBtn", "click", function(event)
{
if(current+1 == favoriteList.length)
{
current = 0;
}
else
{
current = current+1;
}

newText();
});
>>
>>724090621
wow you're a good! thank you so much
>>
I'm guessing your next lesson will probably be adding the ability to remove objects from the array as well. That's a bit trickier, as you'll also have to adjust current. However, you should be able to just manually call the event for lastBtn each time you remove from the array.

Oh, and you could add another if block to each of the events to simply return if favoriteList.length == 0. That'd also be an out of bounds error.

>>724091024
>wow you're a good! thank you so much
Eh, no problem! What language is this, anyhow? I thought it was C# at first, but I'm not sure.
>>
>>724091219
I believe it's java. I can now proudly say that 4chan has helped me more than my teacher did
>>
>>724090621
>>724091024
>>724091219
Oh, and here's a similar modification to the lastbtn event as well.

onEvent("lastBtn", "click", function(event)
{
if(current-1 < 0)
{
current = favoriteList.length-1;
}
else
{
current = current-1;
}
newText();
});

>>724091632
>I believe it's java. I can now proudly say that 4chan has helped me more than my teacher did
Oh, Java? Ick. I've done a lot of Java programming. You should move to C#, though. It's very similar to Java, but it's much easier to use.
>>
>>724092025
I'm kinda inexperience as this is my first year doing this, but really thank you so much for helping me you made my day become more positive!
>>
>>724092638
You're very welcome! Interesting that you're starting out with Java (My first CS1 & 2 classes were C++), but yeah, programming takes a bit for it to actually click. Once it does though, you're golden.

Anyway, good night anon! Please keep experimenting with your code and make it do everything you want it to.
>>
>>724092925
Good night anon-god
Thread posts: 18
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.