2 posts were merged into an existing topic: Assessment for “Marking up a letter”
Hi @chrisdavidmills!!! How are you? Sorry for my disappearance! hehe, we’re working a lot over here! And now… I came back with my questions! hehe
I’m on the first septs of Java Script and cannot understand why after the second line you use “[i]”. I hope don’t bother you with sth maybe silly! Have a nice day!
Active learning: Printing those products!
for(var i = 0; i < products.length; i++) {
var subArray = products[i].split(':');
var name = subArray[0];
var price = Number(subArray[1]);
total += price;
itemText = name + ' — $' + price;
Hi, thanks for creating all these lessons! I’ve been using some time off work to study JavaScript here at your awesome website.
I got all the way thru to your IndexedDB notes demo lesson with very few problems. https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs/Client-side_storage
But now I’ve got some strange problems with the ‘notes demo’ exercise. It works in some places, but not others.
I can get my code to work when I upload to my server and view it on my iPhone in either Chrome or Safari.
I can also get my code to work when I use Safari on my 2016 macbook. Here is my code:
http://websterart.com/html/study-js/toDoIndexed/indexed.html
But my code will not work when I view the same page in Chrome or Firefox on my macbook.
However, when I posted the exact same code at codepen, it works great in Chrome on my macbook:
But that same code won’t work locally on my macbook in Chrome, Firefox or Safari, I’m using xxamp.
http://localhost/www/html/study-js/toDoIndexed/indexed.html
Anytime the code won’t work, whether it’s local on my macbook, or online in Chrome on my server http://websterart.com/html/study-js/toDoIndexed/indexed.html
It throws this error:
////
Uncaught DOMException: Failed to execute ‘transaction’ on ‘IDBDatabase’: One of the specified object stores was not found. “and it says the error is on line 97 of my indexed.js file.
////
Any thoughts? I love this little toDo note app and would like to pretty it up if I could get it working everywhere.
Thanks for looking into it,
mark webster
websterart.com
@maurodibert Loop structures (<for>
) are used to run across a list of elements and somehow either work with those elements or apply something to them. In our assessment the idea is to take every element of our original list (elements of the form name:price
), split each element and then total them up and print the desire string in the list. But to be able to work with each of those elements (name:price
), we need a “index” variable that can take the values from 0 to 4 (less than products.length
) and the variable (index) used is “i
” . And of course as the course had explained, if you have a list and want to accesss an element of the list you need to use listName[positionIndex]
.
I hope I was able to help you. If you still have any doubts, let me know; I can give you more code examples about working with lists using loops.
Hey there, I was having trouble understanding the Looping code section, the Active learning: Filling in a guest list. The last part of the code refused.textContent = refused.textContent.slice(0,refused.textContent.length-2) + '.'; admitted.textContent = admitted.textContent.slice(0,admitted.textContent.length-2) + '.';
kind of baffles me. Basically, I don’t understand how .textContent.length-2
works… what it does to the output.
@maurodibert Hi Mauro! Sorry for missing this for so long ;-| @2alin is pretty much correct.
- Array values are read using bracket notation, so for example you can read the second value of an array with
myArray[1]
(remember computers count from 0, not 1!) - In this case we are looping through all the values inside the
products
array using afor()
loop. - Each time the loop runs, the value of
i
increases by 1, so the first time it runs,products[i]
is equal toproducts[0]
, then second time it isproducts[1]
, and so on.