P
P
petrro2019-10-12 20:02:58
Python
petrro, 2019-10-12 20:02:58

How to pass a for loop to the forEach method without changing anything (or almost nothing) in the code except for the for loop itself?

I have an image slider with buttons below the images:
https://jsfiddle.net/g4roc9m8/1/
How can I replace the for loop with the forEach method in this slider without changing anything in other parts of the code (or changing at a minimum)? I found a slider with the forEach method on the Internet, but there are some remainders from division and in general the code is written too intricately for me personally...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
X
Xaip, 2018-07-15
@Xaip

Wrong line break at least

url = f"https://query.yahooapis.com/v1/public/yql?q="\
              + f"select%20*%20from%20weather.forecast%20where%20w" \
              + f"oeid%20in%20(select%20woeid%20from%20geo.places("\
              + f"1)%20where%20text%3D%22{city}%22)%20and%20u%3D%2" \
              + f"7c%27&format=json&env=store%3A%2F%2Fdatatables.o" \
              + f"rg%2Falltableswithkeys"

And why did you create so many lines? You literally created 6 strings and concatenated them. If you really want to take advantage of the new feature, then use a multi-line comment url = f"""String {city} """

A
ariezzz_python, 2018-07-17
@ariezzz_python

It is not necessary to explicitly specify string concatenation at all. you can do this:
url = " https://query.yahooapis.com/v1/public/yql?q= "\
"select%20*%20from%20weather.forecast%20where%20w" \
"oeid%20in%20 (select%20woeid%20from%20geo.places("\
f"1)%20where%20text%3D%22{city}%22)%20and%20u%3D%2" \
"7c%27&format=json&env=store% 3A%2F%2Fdatatables.o" \
"rg%2Falltableswithkeys"

H
hzzzzl, 2019-10-12
@petrro

images.forEach((img, i) => {
  img.style.display = (i === index - 1) ? 'block' : 'none'
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question