Write a program to give advice on how many dogs people shoul
Write a program to give advice on how many dogs people should have. The program starts like this:
The user puts a number in cell B1, and clicks the button. Advice appears:
Use this table:
Here’s some code. You don’t have to use it.
| Dogs | Advice |
| 0 | Get some dogs! |
| 1 | Get another dog. |
| 2 | That’s the right number of dogs. |
| More than 2 | You have too many dogs. |
Solution
you can get the desired result using a html page , the code is as follows :
<html>
<head>
<title>Dogs advisior</title>
<!-- Latest compiled and minified CSS -->
<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\" integrity=\"sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u\" crossorigin=\"anonymous\">
<!-- Optional theme -->
<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css\" integrity=\"sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp\" crossorigin=\"anonymous\">
<!-- Latest compiled and minified JavaScript -->
<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js\" integrity=\"sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa\" crossorigin=\"anonymous\"></script>
</head>
<body>
<div class=\"container\">
<div class=\"row\" style=\"margin-top:30px;\">
<div class=\"well\">
<div class=\"col-lg-4\">
<p>How many dogs do you have?</p>
</div>
<div class=\"col-lg-4\">
<input type=\"text\" placeholder=\"type your response here\" id=\"response\">
</div>
<div class=\"col-lg-4\">
<button class=\"btn btn-primary\" onclick=\"advise()\">Run</button>
</div>
</div>
</div>
<div class=\"row\">
<div class=\"well\" >Advice: <span id=\"hidden\"></span</div>
</div>
</div>
<script type=\"text/javascript\">
function advise()
{
var res=document.getElementById(\'response\').value;
var set_text=document.getElementById(\'hidden\');
if(res==0)
{
set_text.innerHTML=\"Get some dogs!\";
}
if(res==1)
{
set_text.innerHTML=\"Get another dog.\";
}
if(res==2)
{
set_text.innerHTML=\"That’s the right number of dogs\";
}
if (res>2)
{
set_text.innerHTML=\"You have too many dogs\";
}
}
</script>
</body>
</html>
on ruunig this page you will get the expected result.
how to run : just save the code in a flle and name it with .html extension , after saving locate the file just double click on it . That\'s all

