I have made a color mixer.The div starts out black and you add red values of (1,5 or 10) blue values (1, 5, or 10) and green values(1, 5, or 10) to change the color. The code works I just need some help with the last part. When you click on one of the 9 buttons I need to calculate the RGB code below the div. I cannot figure this part out. I was wondering if I could get some guidance with the javascript to make the rgb calculation to show up below the div.
//get elements
var dvSpeak = document.querySelector("#speak");
var btnOne = document.querySelector("#btnOne");
var btnTwo = document.querySelector("#btnTwo");
var btnThree = document.querySelector("#btnThree");
var btnFour = document.querySelector("#btnFour");
var btnFive = document.querySelector("#btnFive");
var btnSix = document.querySelector("#btnSix");
var btnSeven = document.querySelector("#btnSeven");
var btnEight = document.querySelector("#btnEight");
var btnNine = document.querySelector("#btnNine");
var colorDiv = document.querySelector("#colorDiv");
var redVal = 0;
var blueVal = 0;
var greenVal = 0;
//add event listeners
btnOne.addEventListener("click", dealWithAClick1);
btnTwo.addEventListener("click", dealWithAClick2);
btnThree.addEventListener("click", dealWithAClick3);
btnFour.addEventListener("click", dealWithAClick4);
btnFive.addEventListener("click", dealWithAClick5);
btnSix.addEventListener("click", dealWithAClick6);
btnSeven.addEventListener("click", dealWithAClick7);
btnEight.addEventListener("click", dealWithAClick8);
btnNine.addEventListener("click", dealWithAClick9);
//i would actually call this function colorChange
function dealWithAClick1(event) {
redVal = redVal + 1;
colorChange();
}
function dealWithAClick2(event) {
blueVal = blueVal + 1;
colorChange();
}
function dealWithAClick3(event) {
greenVal = greenVal + 1;
colorChange();
}
function dealWithAClick4(event) {
redVal = redVal + 5;
colorChange();
}
function dealWithAClick5(event) {
blueVal = blueVal + 5;
colorChange();
}
function dealWithAClick6(event) {
greenVal = greenVal + 5;
colorChange();
}
function dealWithAClick7(event) {
redVal = redVal + 10;
colorChange();
}
function dealWithAClick8(event) {
blueVal = blueVal + 10;
colorChange();
}
function dealWithAClick9(event) {
greenVal = greenVal + 10;
colorChange();
}
function colorChange() {
colorDiv.style.backgroundColor = "rgb(" + redVal + "," + greenVal + "," + blueVal + ")"
}
//
body {
background-color: black;
text-align: center;
}
#speak {
color: #555;
}
#colorDiv {
height: 300px;
width: 590px;
background-color: black;
margin: auto;
}
#btnOne {
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
font-weight: bold;
cursor: pointer;
background-color: #FF0000;
width: 187px;
}
#btnTwo {
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
font-weight: bold;
cursor: pointer;
background-color: #0000FF;
width: 187px;
}
#btnThree {
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
font-weight: bold;
cursor: pointer;
background-color: #00FF00;
width: 187px;
}
#btnFour {
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
font-weight: bold;
cursor: pointer;
background-color: #FF0000;
width: 187px;
}
#btnFive {
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
font-weight: bold;
cursor: pointer;
background-color: #0000FF;
width: 187px;
}
#btnSix {
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
font-weight: bold;
cursor: pointer;
background-color: #00FF00;
width: 187px;
}
#btnSeven {
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
font-weight: bold;
cursor: pointer;
background-color: #FF0000;
width: 207px;
}
#btnEight {
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
font-weight: bold;
cursor: pointer;
background-color: #0000FF;
width: 207px;
}
#btnNine {
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
font-weight: bold;
cursor: pointer;
background-color: #00FF00;
width: 207px;
}
#buttons {
width: 600px;
padding: 10px;
margin: auto;
border: 5px solid black;
}
#wholeBox {
width: 700px;
height: auto;
padding: 10px;
border: 10px solid red;
margin: auto;
background-color: white;
}
<div id="wholeBox">
<h1> Color Mixer </h1>
<div id="colorDiv"></div>
<br>
<div id="rgbCode"></div>
<br>
<br>
<div id="buttons">
<button id="btnOne" value="1">Add 1 to red</button>
<button id="btnFour" value="5">add 5 to red</button>
<button id="btnSeven" value="10">add 10 to red</button>
<br>
<button id="btnTwo" value="1">add 1 to blue</button>
<button id="btnFive" value="5">add 5 to blue</button>
<button id="btnEight" value="10">add 10 to blue</button>
<br>
<button id="btnThree" value="1">add 1 to green</button>
<button id="btnSix" value="5">add 5 to green</button>
<button id="btnNine" value="10">add 10 to green</button>
</div>
</div>