Mahendy Arya Putra Airlangga - 152111513011 - Tugastpk
Mahendy Arya Putra Airlangga - 152111513011 - Tugastpk
Mahendy Arya Putra Airlangga - 152111513011 - Tugastpk
152111513011
1. Counter.js
Deskripsi : berfungsi seperti alat bantu hitung untuk menambah atau mengurangi jumlah suatu objek
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-
to-fit=no">
<title>number</title>
<style>
.bg{
background-color: rgba(0, 0, 0, 0.2);
}
</style>
</head>
<body>
function add() {
let add = localStorage.getItem(number);
add++;
localStorage.setItem(number, add)
counter.innerText = localStorage.getItem(number)
console.log(localStorage.getItem(number))
}
function lower(){
let lower = localStorage.getItem(number);
lower-=1;
localStorage.setItem(number, lower)
counter.innerText = localStorage.getItem(number)
console.log(localStorage.getItem(number))
}
function reset(){
let reset = localStorage.removeItem(number);
counter.innerText = "0"
console.log(localStorage.getItem(number))
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
font-family: sans-serif;
}
.content{
/* border: 2px solid black; */
padding: 8px;
margin: auto;
width: 60%;
text-align: center;
box-sizing: border-box;
/* position:relative; */
}
.btn-gamau{
position: absolute;
background:linear-gradient(red, pink) ;
/* margin-left: 8px; */
}
.mau {
background:linear-gradient(green, yellowgreen);
}
.btn {
padding: 10px;
width: 90px;
border-radius: 10px;
color: white;
font-size: large;
}
@media (max-width:600px){
.content{
width: 100%;
box-sizing: border-box;
}
/* .btn-gamau{
position: absolute;
top: 65%;
left: 39%;
} */
}
</style>
</head>
<body>
<div class="content">
<h1>Moving Button</h1>
<img
src="https://i.pinimg.com/originals/63/21/fa/6321fa6690d59b2f37c25ce0d271cb6c.gif
" alt="">
<h1>Coba Klik Tombol Warna Merah ! (cek console)</h1>
<button id="btn-mau" class="btn mau">Hijau</button>
<button id="btn-gamau" class="btn-gamau btn"
onmousemove="gamau(this)">Merah</button>
</div>
<script>
function mau() {
alert("Button Hijau di Klik")
}
document.getElementById("btn-mau").onclick = mau
function gamau(id) {
let mau = document.getElementById("btn-mau");
let i = Math.floor(Math.random() *300)+1;
let j = Math.floor(Math.random() *100) + mau.offsetTop
id.style.left = i + 'px';
id.style.top = j + "px"
console.log(i + 'px'+ ',' + j + "px")
}
</script>
</body>
</html>
Hasil kordinat yang didapat secara acak akan ditampilkan pada console
3. event.js
Deskripsi : menampilkan event secara langsung pada java script tanpa loading Ketika pengguna menekan
button sebanyak 7 kali
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
.content {
/* width: 40%; */
padding: 12px;
box-sizing: border-box;
border: 5px solid black;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.content button {
margin-top: 10px;
margin-bottom: 10px;
}
</style>
<body onload="welcome()">
<div class="content" hidden id="content">
<button id="button">
Kamu klik aku
</button>
<p id="awal">
kamu sudah mengklik aku sebanyak <span id="show">0</span> kali
</p>
</div>
<script>
let welcome = () => {
alert("Assalamualaikum")
const content = document.getElementById("content");
content.removeAttribute("hidden")
}
</script>
</body>
</html>
Dan banyaknya jumlah pengguna menekan tombol akan di tampilkan lewat console