Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,224 members, 7,815,282 topics. Date: Thursday, 02 May 2024 at 10:12 AM

Help With A Javascript Problem - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help With A Javascript Problem (405 Views)

Everybody Is A Javascript Developer On Nigerian Tech Twitter / Javascript Problem / Help Me With This Javascript Problem (2) (3) (4)

(1) (Reply) (Go Down)

Help With A Javascript Problem by morzook(m): 9:55pm On Sep 02, 2022
I am building a clone of the popular game, 4 pics 1 word and I have an issue I am battling with. As shown in the image, I want to populate the empty boxes with each alphabet clicked from the alphabet options below it.

The issue now is that for each time I click the alphabets, only the first box gets updated. The other three never gets updated. How do I go about it? I can apccess each box by using childNode[index].

Re: Help With A Javascript Problem by Fourpockets: 11:11pm On Sep 02, 2022
morzook:
I am building a clone of the popular game, 4 pics 1 word and I have an issue I am battling with. As shown in the image, I want to populate the empty boxes with each alphabet clicked from the alphabet options below it.

The issue now is that for each time I click the alphabets, only the first box gets updated. The other three never gets updated. How do I go about it? I can apccess each box by using childNode[index].

You could store the values of the letters you clicked in an array, and then map it onto the boxes, everytime you click the letters, run a function to map it, this is the easiest solution I could give off head

1 Like

Re: Help With A Javascript Problem by chukwuebuka65(m): 10:09am On Sep 03, 2022
First , the values for the boxes should be stored and read from an array.
Secondly, I believe your alphabets are also stored and read from array of objects (with id and value properties) that you map through adding a click event that runs the function above ,the id from the object and then creating an <li> tag that contains the alphatbet.
Lastly you need a function should get the e.target.value or map through ur array of alphabets to get the alphabet clicked and then also map through you array of boxes to add the alphabet clicked.
If you didnt understand the above explanation. Maybe you should take a screenshot so we see exactly where the bug is.

1 Like

Re: Help With A Javascript Problem by jbreezy: 10:36am On Sep 03, 2022
It’s because you didn’t increment the index of your box.

1 Like

Re: Help With A Javascript Problem by chukwuebuka65(m): 11:15am On Sep 03, 2022
jbreezy:
It’s because you didn’t increment the index of your box.

If he increments the index of the box. I think its going to get that particular index and still leave out the rest
Re: Help With A Javascript Problem by Sleekcode: 11:53am On Sep 03, 2022
grin grin grin

1. Store ur boxes in array

On button of ur text click loop and check the box arrray n if the first array box value length is greater than 1 since each box can only hold one value.

if the first box in the array is greater than one.... Now move to the next box in the array and let it have the value of the clicked event...

if all your boxes are filled simply add return to stop ur function from doing anything else.


If u remove or edit out a value from any box set the box value on change to 0;.

ur app should work well now
grin

2 Likes

Re: Help With A Javascript Problem by dragnet: 12:10pm On Sep 03, 2022
display your code
Re: Help With A Javascript Problem by Karleb(m): 12:15pm On Sep 03, 2022
How are you people debugging without seeing the code?

Are you guys witches? undecided

1 Like

Re: Help With A Javascript Problem by LikeAking: 5:17pm On Sep 03, 2022
Op, getat!
Re: Help With A Javascript Problem by niel63(m): 8:23pm On Sep 03, 2022
Even stackoverflow or any other dev forum would always recommend you show some piece of code. An example of what you've attempted that's not working for you.

1 Like

Re: Help With A Javascript Problem by niel63(m): 8:24pm On Sep 03, 2022
LikeAking:
Op, getat!
grin wetin he do you now?

(1) (Reply)

Sometimes It Doesn't Matter What Language / I Just Finished Creating some module of my Crypto Payment Gateway / Boost Your Instagram/tiktok Followers And Tiktok Likes

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 15
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.