scrimba
Note at 0:05
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Note at 0:05
AboutCommentsNotes
Note at 0:05
Expand for more info
index.js
run
preview
console


// javascript
let root = document.documentElement;
let num = 0;

const btn_next = document.getElementById("next");
btn_next.style.backgroundColor = "green";

const btn_previous = document.getElementById("previous");
btn_previous.style.backgroundColor = "green";


btn_next.addEventListener("click", ()=>{
console.log(`Clicked btn_next`);

if(num > -880) {
num-=220;
console.log(num);
root.style.setProperty(`--num`, num + "px");
}

if(num < 0) {
btn_previous.style.opacity = '1';
} else {
btn_previous.style.opacity = '.3';
}

if(num === -880) {
btn_next.style.opacity = ".3";
} else {
btn_next.style.opacity = "1";
}

})

btn_previous.addEventListener("click", ()=>{
console.log(`Clicked btn_previous`);

if(num < 0) {
num+=220;
console.log(num);
root.style.setProperty(`--num`, num + "px");
}

if(num < 0) {
btn_previous.style.opacity = '1';
} else {
btn_previous.style.opacity = '.3';
}

if(num === -880) {
btn_next.style.opacity = ".3";
} else {
btn_next.style.opacity = "1";
}

})
Console
"Clicked btn_next"
,
-220
,
"Clicked btn_next"
,
-440
,
"Clicked btn_next"
,
-660
,
"Clicked btn_next"
,
-880
,
"Clicked btn_next"
,
"Clicked btn_previous"
,
-660
,
"Clicked btn_next"
,
-880
,
"Clicked btn_next"
,
"Clicked btn_previous"
,
-660
,
"Clicked btn_previous"
,
-440
,
"Clicked btn_next"
,
-660
,
"Clicked btn_next"
,
-880
,
"Clicked btn_next"
,
"Clicked btn_next"
,
"Clicked btn_next"
,
"Clicked btn_next"
,
"Clicked btn_next"
,
"Clicked btn_previous"
,
-660
,
"Clicked btn_previous"
,
-440
,
"Clicked btn_previous"
,
-220
,
"Clicked btn_previous"
,
0
,
"Clicked btn_previous"
,
"Clicked btn_previous"
,
"Clicked btn_next"
,
-220
,
"Clicked btn_next"
,
-440
,
/index.html
LIVE