не работает or в if'e в js
but.addEventListener("click", function(e){
let r = randomColor(col.value);
let g = randomColor(col.value);
let b = randomColor(col.value);
if (col.value="red"){
if ((r<g) or (r<b)){
if (g>b){
r=g;
}else{
r=b;
}
g=g/2;
b=b/2;
}
}
Это кусок кода, не спрашиваете что там происходит)) у меня в 6 строчке не работает Or, ошибка такая -
Uncaught SyntaxError: Unexpected identifier
гуглил и пробовал ||, ошибка слегка меняется но все равно не работает. Я с с++ перешел только на js, еще не освоился
Ответы (1 шт):
Автор решения: Andrey Semykin
→ Ссылка
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA Compatible" content="IE=edge">
<title>test</title>
<style>
</style>
</head>
<body>
<input type="text" value="Поле ввода" id="col">
<button id="but">я кнопка</button>
<script>
'use strict'
function randInt(min, max){
return (Math.floor(Math.random() * (max - min)) + min);
}
function randomColor(a){
if (a==''){
let a = randInt(0, 255);
let b = randInt(0, 255);
let c = randInt(0, 255);
return [a, b, c];
}
if (a=="red"){
let a = randInt(0, 255);
let b = 0;
let c = 0;
return [a, b, c];
}
if (a=="blue"){
let a = 0;
let b = 0;
let c = randInt(0, 255);
return [a, b, c];
}
if (a=="green"){
let a = 0;
let b = randInt(0, 255);
let c = 0;
return [a, b, c]
}
}
function decToHex(n) {
return n.toString(16);
}
but.addEventListener("click", function(e){
console.log('col', col.value)
let rgbArray = randomColor(col.value);
console.log('rgbArray', rgbArray);
document.body.style.backgroundColor = `rgb(${rgbArray[0]},${rgbArray[1]},${rgbArray[2]})`;
});
</script>
</body>