Created
June 18, 2024 09:31
-
-
Save swdevbali/ebce79d5d7b8118b1669d82a2da55f50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("Script started"); | |
let quotesArray = [ | |
{ | |
"quote": "Banyak bicara, banyak bekerja", | |
"author": "Bung Karno" | |
}, | |
{ | |
"quote": "Habis gelap terbitlah terang", | |
"author": "R.A Kartini" | |
} | |
] | |
let indexCurrentItem = 0; | |
huruf = ['a', 'b', 'c', 'd', 'e', 'f']; //array, hanya bisa diakses dengan angka ordinal 0 ... len-1 | |
console.log("huruf", huruf); | |
console.log(huruf[3]); | |
hurufmap = { | |
'a': 'Huruf A', | |
"b": 'Huruf B', | |
'c': "Huruf C", | |
} | |
console.log("hurufmap",hurufmap); | |
console.log(hurufmap['a']); | |
//Tugas: ambil huruf ke 5 dan hurufmap dengan key 'c' | |
function prevQuote(){ | |
console.log("prevQuote"); | |
// jika index sudah == 0, jangan dikurang | |
if(indexCurrentItem > 0) indexCurrentItem--; | |
displayQuote(); | |
} | |
function displayQuote() { | |
let quoteAuthor =""; | |
let quoteContent=""; | |
quoteContent = quotesArray[indexCurrentItem].quote; | |
quoteAuthor = quotesArray[indexCurrentItem].author; | |
console.log("Menampilkan quote dari ", quoteAuthor, ":", quoteContent); | |
document.getElementById("quoteContent").innerText = quoteContent; | |
document.getElementById("quoteAuthor").innerText = quoteAuthor; | |
} | |
function nextQuote(){ | |
console.log("nextQuote"); | |
// let x = 2; | |
// x = 3; | |
// console.log(x); | |
// const pi = 3.14; | |
// pi = 10; | |
// console.log("pi", pi); | |
if(indexCurrentItem < quotesArray.length - 1 ) indexCurrentItem++; //1 off error | |
displayQuote(); | |
} | |
//DOM: DOcument Object Model => HTML | |
document.addEventListener("DOMContentLoaded", function(){ | |
displayQuote(); | |
}); | |
/* | |
PE ER: Jika index sudah di ujung2, maka buat tombol yang sesuai menjadi cursor normal (yang sekarang cursor pointer) | |
dan warnanya greyed. Minta chatgpt buatin, tapi terus pahami. | |
*/ | |
function addQuote(){ | |
console.log("addQuote"); | |
const formQuote = document.getElementById("formQuote"); | |
formQuote.classList.remove("hidden"); | |
} | |
function saveQuote(){ | |
console.log("saveQuote"); | |
const formQuote = document.getElementById("formQuote"); | |
formQuote.classList.add("hidden"); | |
} | |
function cancel(){ | |
console.log("saveQuote"); | |
const formQuote = document.getElementById("formQuote"); | |
formQuote.classList.add("hidden"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment