Boa tarde, conclui o código com sucesso, peço uma avaliação para confirmar.
https://alpha.sandstorm.io/shared/B7wlyp-K6bNu9F2YLU5A1OKjifhGJv8U5SdATwY3dGW
Hi @Elcio_Bernardo_Souto and welcome to the community
When I open your link I just get an error message
Invalid token: B7wlyp-K6bNu9F2YLU5A1OKjifhGJv8U5SdATwY3dGW
Can you please check your link is correct?
Thanks and have a nice day!
Michael
Bom dia michael o link expirou.
Mas peco para tentar este em baixo
Hi again, @Elcio_Bernardo_Souto
Thanks for putting the code on GitHub. I had a look and here is my feedback:
-
You have a lot of repetition in your code. This is often a sign that we can improve it. For example inside the
for
loop you have a lot ofif...else
statements with nearly the same content. Only the numbers in the image names differ. Since we have our loop variablei
that goes from 1 to 5, we could use that to build our image names.Instead of
/* "xxx" was meant as a placeholder for your own code */ newImage.setAttribute('src', xxx);
you could delete the
if...else
statements and usenewImage.setAttribute('src', 'images/pic' + i + '.jpg');
-
A similar case is your
thumbBar.onclick
event handler. Instead of attaching the event handler tothumbBar
we could attach events to every image inside thefor
loop:newImage.onclick = function(e) { displayedImage.src = e.target.src; }
-
Your code for the “Darken/Lighten” button looks good!
You could even delete the secondif
statement and just use} else {
since there are only two possibilities (class=“dark” or class=“light”)
I hope this feedback helps you. Feel free to ask questions. I’m happy to help.
Have a nice day!
Michael
Muito obrigado por me ajudar a melhorar o meu código @mikoMK,
realmente tinha muitos ‘loops’, mas como sou iniciante, vou aprendendo com o tempo!
peço que continue a ajudar-me
You are very welcome! I’m glad it was helpful.
When you start learning loops it’s pretty hard to understand it. But once you get it, it’s just wonderful to see how small code is able to do big work. I promise when you keep learning, some day you just naturally understand it and know how to use the advantages of loops.
Michael