السلام عليكم اخوتي الاعزاء مشاهدين هذا الطلب
هذا كود لأدة تحويل كود الوان hex الي كود الوان rgb علام اعتقد ان الخطا في javascript ولا استطيع اصلاحة واتمني ان يصلحه احد لي وشكرا
<style>
@import url("https://fonts.googleapis.com/css?family=Montserrat:400,400i,700");
:root {
--shortTiming: 0.3s;
--timing: 1.5s;
--longTiming: 3s;
--converter-color: white;
}
body {
margin: 0;
padding: 0;
width: 100vw;
overflow-x: hidden;
box-sizing: border-box;
font-family: "Montserrat";
background: #f5f5f5;
}
body *,
body *:after,
body *:before {
box-sizing: inherit;
}
* {
position: relative;
}
.color-block {
width: 100px;
height: 100%;
background: var(--color-block-bg);
border-radius: 8px;
box-shadow: 0 0.5vmin 1vmin rgba(0, 0, 0, 0.1);
margin-bottom: 2rem;
}
#converter .error {
color: #e57373;
}
#converter .color-block {
display: flex;
justify-content: center;
align-items: center;
background: var(--converter-color);
width: 300px;
height: 100px;
}
#converter .converter__hex {
display: flex;
height: 4rem;
align-items: center;
border-radius: 8px;
max-width: 400px;
overflow: hidden;
background: #37474f;
color: white;
}
#converter .converter__hex .hash {
padding: 10px;
width: 30px;
display: inline-block;
}
#converter .converter__hex input {
flex: 2;
min-width: 100px;
height: 100%;
font-size: 2rem;
padding-left: 10px;
letter-spacing: 5px;
color: #37474f;
margin: 0;
}
#converter .converter__hex button {
border: none;
margin: 0;
-webkit-appearance: button;
height: 100%;
flex: 1;
background: #9575cd;
outline: none;
color: white;
font-size: 1rem;
}
#converter .converter__hex button:hover {
background: #37474f;
}
</style>
<div class="divider from-guide">
👍
<h3>Great work, You did it!!!</h3>
</div>
<section class="converter">
<h2>In case you didnt do the math with us</h2>
<p>Here is a hex to rgb converter that uses the above algorithm.</p>
<div id="converter">
<h3>Hex 2 RGB Converter</h3>
<div class="converter__wrapper">
<div class="color-block">rgb(255,255,255)</div>
<div class="converter__hex">
<span class="hash">#</span> <input type="text" />
<button>convert</button>
</div>
<div class="error"></div>
</div>
</div>
<script>
//converter
const newError = msg => {
const errorTag = document.querySelector(".error");
errorTag.innerHTML = msg;
};
const removeError = () => {
const errorTag = document.querySelector(".error");
errorTag.innerHTML = "";
};
const base16 = {
0: 0,
1: 1,
2: 2,
3: 3,
4: 4,
5: 5,
6: 6,
7: 7,
8: 8,
9: 9,
a: 10,
b: 11,
c: 12,
d: 13,
e: 14,
f: 15
};
const convertBtn = document.querySelector("#converter button");
convertBtn.addEventListener("click", function() {
removeError();
const input = document.querySelector("#converter input").value;
if (input.length !== 6) return newError("must have exactly 6 values");
const hex = input.split("");
const r = hex
.splice(0, 2)
.map((n, index) => (index === 1 ? base16[n] : 16 * base16[n]))
.reduce((total, n) => total + n, 0);
const g = hex
.splice(0, 2)
.map((n, index) => (index === 1 ? base16[n] : 16 * base16[n]))
.reduce((total, n) => total + n, 0);
const b = hex
.splice(0, 2)
.map((n, index) => (index === 1 ? base16[n] : 16 * base16[n]))
.reduce((total, n) => total + n, 0);
if (isNaN(r) || isNaN