Introduction to JavaScript Workshop

  1. function replaceImagesWithUrl(url) {
  2. // Get all img elements in the document
  3. var images = document.getElementsByTagName('img');
  4.  
  5. // Convert images NodeList to an array and iterate using forEach
  6. Array.from(images).forEach(function(img) {
  7. // Replace the src attribute with the provided URL
  8. img.src = url;
  9. });
  10. }
  1. function replaceSpanText(newText) {
  2. // Get all span elements in the document
  3. var spans = document.getElementsByTagName('span');
  4.  
  5. // Convert NodeList to an array and iterate using forEach
  6. Array.from(spans).forEach(function(span) {
  7. // Replace the text content of the span with the provided new text (string
  8. span.textContent = newText;
  9. });
  10. }
( ) parentheses, brackets
{ } curly brackets, curly braces
' '  single quotes
" " double quotes
, comma
. period, dot
- dash, hyphen
_ underscore
/ slash
\ backslash
argument = the input to a function
call a function = use a function, make it do what it's intended to do
put the argument between the parentheses when you call a function
declare a function
return = the value that a function returns or gives back when it is called
string = text data which is determined by a pair of quotes, single or double
variable = a box with a name in which we can store things
  • intro-to-javascript-wokshop.txt
  • Last modified: 5 months ago
  • by renick