A
A
Alexandra2019-07-19 16:38:56
JavaScript
Alexandra, 2019-07-19 16:38:56

Stuck on a task in Yandex.Practical JS code. What's wrong?

Task:
At the end of the script, apply a background color to the body of the HTML document, the value of which is the result of calling the makeColorString(r, g, b) function with the red, green, and blue parameters. The line with this call is now the last one in script.js.

var red = 255;
var green = 0;
var blue = 0;
var bgValue = 'rgb(' + red + ', ' + green + ', ' + blue + ')';
console.log(bgValue);
var red = prompt('Введите насыщенность цвета в виде числа от 0 до 255', '255');
var green = prompt('Введите насыщенность цвета в виде числа от 0 до 255', '0');
var blue = prompt('Введите насыщенность цвета в виде числа от 0 до 255', '0');
function checkInput(i) {
  i = Number(i);
function makeColorString (r, g, b) {
var bgValue = 'rgb(' + i + ', ' + g + ', ' + b + ')';
return(bgValue);
console.log (i + b);
console.log ('Вы определили насыщенность цвета как ' + i);
}
  return i
}
red = checkInput(red);
green = checkInput(green);
blue = checkInput(blue);
document.write(makeColorString(red, green, blue));

I insert it at the very bottom (there is a hint for fools, insert this line):
document.body.style.backgroundColor = makeColorString(red, green, blue);
Throws: "makeColorString function returns wrong result"

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rsa97, 2019-07-19
@Rsa97

And let's just write your code with normal indents

function checkInput(i) {
  i = Number(i);
  function makeColorString (r, g, b) {
    var bgValue = 'rgb(' + i + ', ' + g + ', ' + b + ')';
    return(bgValue);
    console.log (i + b);
    console.log ('Вы определили насыщенность цвета как ' + i);
  }
  return i
}

Do you notice anything strange? Why do you define a function inside another function? Why are there lines of output to the console after returning from the function?

M
mad_god, 2019-07-19
@mad_god

function makeColorString (r, g, b) {
var bgValue = 'rgb(' + i + ', ' + g + ', ' + b + ')';
instead of i - r did not try? Why is i there?

A
Alexandra, 2019-07-19
@Forum_0

In the previous tasks, you had to write a function within a function. I don't know why I have lines of output to the console after returning from the function))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question