Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9175383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:54:16+00:00 2026-06-17T16:54:16+00:00

<html> <head> <title> Colors </title> </head> <body> <script type=text/javascript> var a = parseInt(prompt(Enter R));

  • 0
<html>
    <head>
        <title> Colors </title>
    </head>

    <body>
    <script type="text/javascript">
        var a = parseInt(prompt("Enter R"));
        var b = parseInt(prompt("Enter G"));
        var c = parseInt(prompt("Enter B"));
        document.body.style.backgroundColor=rgb(a,b,c);
    </script>
    </body>
</html>

Why doesn’t the background color change according to the RGB values? What have I done wrong??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:54:17+00:00Added an answer on June 17, 2026 at 4:54 pm

    You need to use quotes:

    document.body.style.backgroundColor = 'rgb(' + a + ',' + b + ',' + c + ')';
    

    JS Fiddle demo.

    Or:

    document.body.style.backgroundColor = 'rgb(' + [a,b,c].join(',') + ')';
    

    JS Fiddle demo.

    Unquoted the JavaScript is passing the variables, as arguments, a,b and c to an undefined function called rgb(). As you’re setting a CSS property you need to pass a string, hence the requirement of quoting.

    Oh, and also you’re using parseInt() which doesn’t require a radix to be passed in, but it’s better (and easier to avoid problems) if you do (the radix being the expected number-base):

    var a = parseInt(prompt("Enter R"), 10) || 255,
        b = parseInt(prompt("Enter G"), 10) || 255,
        c = parseInt(prompt("Enter B"), 10) || 255;
    

    JS Fiddle demo (In the demo I use 105 just so it’s clear the default is being used if the cancel button is used).

    And if someone hits ‘cancel’ on the prompt, you might want to supply a default argument to ensure that an actual colour-value is passed, since cancel otherwise, I think, evaluates to false (I’m assuming you’d prefer 255, but obviously adjust to taste).

    You could also, of course, simply define a function:

    function rgb(r,g,b) {
        return 'rgb(' + [(r||0),(g||0),(b||0)].join(',') + ')';
    }
      var a = parseInt(prompt("Enter R"), 10),
          b = parseInt(prompt("Enter G"), 10),
          c = parseInt(prompt("Enter B"), 10);
      document.body.style.backgroundColor = rgb(a,b,c);
    

    JS Fiddle demo

    And this approach has the (perhaps specious) benefit of allowing a custom default value to be used:

    function rgb(r,g,b, def) {
    def = parseInt(def, 10) || 0;
        return 'rgb(' + [(r||def),(g||def),(b||def)].join(',') + ')';
    }
    var a = parseInt(prompt("Enter R"), 10),
        b = parseInt(prompt("Enter G"), 10),
        c = parseInt(prompt("Enter B"), 10);
    document.body.style.backgroundColor = rgb(a,b,c,40);
    

    JS Fiddle demo

    References:

    • || (logical OR) operator.
    • Array.join().
    • Element.style.
    • parseInt().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<HTML> <HEAD> <title>Login</title> <script type=text/javascript src=http://script.auction.co.kr/common/jquery.js></script> <script type=text/javascript> $(document).ready(function() { $(:input[name='txtPassword']).blur(function(e){ $(this).css(background-color,white); }); $(:input[name='txtPassword']).focus(function(e){
Take a look at this html: <head> <title>Test page</title> <script type=text/javascript> function submitForm() {
Heres my simple html source <html> <head> <title> Dec2Bin </title> <script type=text/javascript> function app()
I have this html code <html> <head> <title>JQuery Problem 2</title> <script type=text/javascript src=jquery-1.4.min.js></script> <script
<html> <head> <meta http-equiv=Content-Type content=text/html; charset=UTF-8> <title>Login Page</title> </head> <br><br><br><br> <body style=background-color: cornflowerblue >
I have some HTML Code: <html> <head> <title>css test</title> <style type=text/css> .box{width:100%;float:left;background:red} </style> </head>
I have my registerUsers.html as below <html> <head> <title>userlogin</title> </head> <body> <h1><center>User login</center></h1> <p>
Basicily i have a index.html shown below.. <html> <head> <title>UI Test: Main Menu</title> <script
My code as follow: <html xmlns=http://www.w3.org/1999/xhtml> <head> <meta http-equiv=content-type content=text/html; charset=UTF-8> <title>Demo</title> <style type=text/css>
I'm breaking my head over this code: <html> <head> <title>Westpop</title> <link rel=stylesheet href=opmaak.css> </head>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.