That is the elephant in the room that was bound to come up, eventually. How often do we see a naive learner who wishes to side step the rudiments and fundamentals in favor of the finished product (that they copy)? They see it work and think it is simple to learn from only to find it is not quite so easy.
I know that its āJavaScriptā as you clearly see in the beginning of this Post I didnāt think I had to keep fully spelling it out for everybody . Anyway I know I have to learn more about āJavaScriptā and I will in the near future. I just wanted to try this code I found to use this specific Slider. Below is how I originally had it setup. I already have a basic understanding of variables, value, strings, Boolean, numbers, and properties. I just thought I could be guided in the right direction with this specific code to make it work which iām clearly not getting from you or @mtf, you doing a lot of critiquing about unnecessary things and less explaining the code I have, If you canāt focus on helping me with this code than you can stop replying because so far your not helping at all. I thought this forum is a place to get help??
var img = document.getElementById(āimgsā);
var imag = [āpic1.jpgā, āpic2.jpgā, āpic3.jpgā, āpic4.jpgā];
var x = 0;
function slide(){
if (x < imag.length) {
x = x + 1;
} else {
x = 1;
}
img.innerHTML="";
}
Like @stetim94 has suggested, you are jumping into the deep end then expecting everyone to come forward to help you out. That is not fair to the members. If you cannot take some time on your own to learn the basics, that is, really learn, then you are only wasting our time for your own gratification. Youāll not get very far doing things this way, imho.
And, one thing you will find invaluable in the forum world⦠A thick skin. If you cannot handle a little critiquing then you are in the wrong place.
Dont worry about this part, I know where the quote marks go, I had set it up a certain way so It could post, idk whats going on with this posting maybe the site postās code comments slow or my connection slow Iāll try to be more patient with this posting
Iām not jumping in too deep I just had the wrong expectations about this forum thatās all as I clearly see by constantly going back and forth with you guys. So by the way you guys are commenting this seems to be only a place where people basically help people remember the things they already learned and thatās kool I get that now so my fault for the misunderstanding, and I have thick skin more than you can imagine I donāt mind critiquing but when itās just all I see every other post its a waste of typing back and forth on both sides in my opinion, I look at things on a time basis thatās what was irritating me I felt you were wasting my time I could care less what you or anybody think of me I only care when I fell my time is being played with and I know iām Impatient at times so I Apologize for my impatiences and the misunderstandings⦠By all means I really do plan to learn JavaScript just like I took the time to learn HTML and CSS because I want to be proficient as a Web Designer. I just simply wanted to see this code work real quick and I know thereās a quick help solution to this before I really dig deep in my learning to Javascript if I find it kool if not then oh well either way Iām still going to Really Learn JS in the near future, I just canāt find the quick way to this solution here and Iām kool with that too because I still love this site even as a New member this is were Iām going to spend most of my learning, the courses are very informative, I just canāt put the time right now to get deep in JS with so much I have to get done in my personal life at the moment.
<script>
function slide(){
x += x < imag.length ? 1 : -x;
img.innerHTML = '<img src="assets/' + imag[x - 1] + '">';
}
var img = document.getElementById('imgs');
var imag = ['pic1.jpg', 'pic2.jpg', 'pic3.jpg', 'pic4.jpg'];
var x = 0;
setInterval(slide, 2000);
</script>
The slide function you already know about, but ternary expressions are a long ways up the learning curve, though not hard to understand. The ternary operator ? follows a conditional expression. Depending upon that boolean, the first parameter is assigned (true) otherwise the second parameter is assigned. Furthermore, in the above example we used a compound assignment operator which is the equivalent of x = x + ?.
Letās walk that through. given a length of 4.
1. x is 0
2. setInterval invokes callback
3. x is less than 4 so has 1 added
4. imag[0] is passed to the DOM interpolated in an IMG tag
5. x is 1, invoke callback
6. x becomes 2
7. imag[1] is passed to DOM
8. x is 2, invoke callback
9. x becomes 3
10. imag[2] displays
11. x is 3, invoke callback
12. x becomes 4
13. imag[3] displays
14. x is 4, invoke callback
15. x becomes 4 - 4 => back to line 1