diff --git a/week-3/spongebob/.gitignore b/week-3/spongebob/.gitignore new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/week-3/spongebob/.gitignore @@ -0,0 +1 @@ + diff --git a/week-3/spongebob/README.md b/week-3/spongebob/README.md new file mode 100644 index 0000000..00220f7 --- /dev/null +++ b/week-3/spongebob/README.md @@ -0,0 +1,2 @@ +# Mocking-SpongeBob +Mocking SpongeBob Meme Creator diff --git a/week-3/spongebob/img/spongebob.jpg b/week-3/spongebob/img/spongebob.jpg new file mode 100644 index 0000000..73a683c Binary files /dev/null and b/week-3/spongebob/img/spongebob.jpg differ diff --git a/week-3/spongebob/index.html b/week-3/spongebob/index.html new file mode 100644 index 0000000..d1f38ba --- /dev/null +++ b/week-3/spongebob/index.html @@ -0,0 +1,32 @@ + + + + + + + + + Mocking SpongeBob + + +
+
+ SpongeBob +
+
Mocking SpongBob
+

+ The text above is editable and reformats when you re-focus your cursor. Our developer messed up the code for this SpongeBob Meme. Instead of alternating caps, the title converts to uppercase. Fix this meme by editing the JavaScript function in this code. +

+
+
+
+ + + \ No newline at end of file diff --git a/week-3/spongebob/js/main.js b/week-3/spongebob/js/main.js new file mode 100644 index 0000000..9a8f50c --- /dev/null +++ b/week-3/spongebob/js/main.js @@ -0,0 +1,47 @@ +/** + * Get the editable instance. + */ +let editable = document.querySelector("[contenteditable=true]"); + +/** + * When focus is removed, run the `formatText` function + */ +editable.addEventListener('blur', formatText); + +/** + * Format the innerText of the SpongeBob meme + */ +function formatText(event){ + + // Format the text + let memedText = this.innerText.toLowerCase(); + + let characters = this.innerText.split(""); + // defining characters as string + + let letters =[]; + //creating an array + + characters.forEach((character, index) => { + + if (index % 2 ==1){ + letters.push(character.toUpperCase()); + } else{ + letters.push(character.toLowerCase()); + } + }); + + + + + + + //let nums=[0,1,2,3,4,5] + //nums.forEach(function(num, index){ + //console.log(index % 2 ); + + + + // Replace the old text with new text + this.innerText = letters.join(""); +}