Question

In: Computer Science

<!DOCTYPE html> <html> <head> <!-- *************************************************************************************** --> <!-- * * --> <!-- * Do not change...

<!DOCTYPE html>

<html>

<head>

<!-- *************************************************************************************** -->

<!-- * * -->

<!-- * Do not change anything within the <head></head> section of the HTML * -->

<!-- * * -->

<!-- *************************************************************************************** -->

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>

<style> .btn{border:1px solid black; padding:5px;display:inline-block} </style>

</head>

<body>

<!-- *************************************************************************************** -->

<!-- * * -->

<!-- * Nothing to change here in the <body> * -->

<!-- * * -->

<!-- *************************************************************************************** -->

<h1>Count of Magic numbers</h1>

<p>Enter a number x. Click calculate to determine the number of magic numbers between 1 and x (inclusive).</p>

<p>Your number: <input type="text" id="textEntered1"></p>

<p><input type="button" class="btn btn-primary" id="btn_1" value="Calculate"></p>

<div id="textDisplayed1"></div>

</body>

<script>

//


function isMagicNumber(x) {

////////////////////////////////////////////////////////////////////////////////

// Insert your code between here and the next comment block. Do not alter //

// any code in any other part of this file. //

////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////

// Insert your code between here and the previous comment block. Do not alter //

// any code in any other part of this file. //

/////////////////////////////////////////////////////////////////////////////////

}


function getCount(x) {

////////////////////////////////////////////////////////////////////////////////

// Insert your code between here and the next comment block. Do not alter //

// any code in any other part of this file. //

////////////////////////////////////////////////////////////////////////////////

var numbers = "";

for(var i = 1; i<x; i++)

{

if(isMagicNumber(i))

{

numbers += "" + i + ",";

}

}

return numbers;

/////////////////////////////////////////////////////////////////////////////////

// Insert your code between here and the previous comment block. Do not alter //

// any code in any other part of this file. //

/////////////////////////////////////////////////////////////////////////////////

}



$("#btn_1").click(function(){

var x = $('#textEntered1').val();

$("#textDisplayed1").html(getCount(x));

});

</script>

</html>

Solutions

Expert Solution

Code changes and relevant comments have been added in bold.

<!DOCTYPE html>

<html>

<head>

<!-- *************************************************************************************** -->

<!-- * * -->

<!-- * Do not change anything within the <head></head> section of the HTML * -->

<!-- * * -->

<!-- *************************************************************************************** -->

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>

<style> .btn{border:1px solid black; padding:5px;display:inline-block} </style>

</head>

<body>

<!-- *************************************************************************************** -->

<!-- * * -->

<!-- * Nothing to change here in the <body> * -->

<!-- * * -->

<!-- *************************************************************************************** -->

<h1>Count of Magic numbers</h1>

<p>Enter a number x. Click calculate to determine the number of magic numbers between 1 and x (inclusive).</p>

<p>Your number: <input type="text" id="textEntered1"></p>

<p><input type="button" class="btn btn-primary" id="btn_1" value="Calculate"></p>

<div id="textDisplayed1"></div>

</body>

<script>

//

function isMagicNumber(x) {

var sum = 0;
  
//magic number is when a digits of a number are added till the point, sum becomes a single digit number and sum is equal to 1
while (x > 0 || sum > 9)
{
if (x == 0)
{
x = sum;
sum = 0;
}
sum += x % 10;
x /= 10;
}
  
// returning true if sum is equal 1.
return (sum == 1);

}

function getCount(x) {

var numbers = "";

for(var i = 1; i<x; i++)

{

if(isMagicNumber(i)) //Checking if number is magic or not

{

numbers += "" + i + ","; // The magic number will be added one by one separated by comma(',')

}

}

return numbers; // The number will be returned as 10,19,28, if the input is 30 for instance.

}


$("#btn_1").click(function(){

var x = $('#textEntered1').val();

$("#textDisplayed1").html(getCount(x));

});

</script>

</html>


Related Solutions

HTML <!DOCTYPE html> <html> <head>     <meta charset="UTF-8">     <title>Clock</title>     <link rel="stylesheet" href="clock.css">    &n
HTML <!DOCTYPE html> <html> <head>     <meta charset="UTF-8">     <title>Clock</title>     <link rel="stylesheet" href="clock.css">     <script src="clock.js"></script> </head> <body>     <main>         <h1>Digital clock</h1>         <fieldset>             <legend>Clock</legend>             <span id="hours">&nbsp;</span>:             <span id="minutes">&nbsp;</span>:             <span id="seconds">&nbsp;</span>&nbsp;             <span id="ampm">&nbsp;</span>         </fieldset>     </main> </body> </html> CSS: body {     font-family: Arial, Helvetica, sans-serif;     background-color: white;     margin: 0 auto;     width: 450px;     border: 3px solid blue;     padding: 0 2em 1em; } h1 {     color: blue; } label {     float: left;     width: 11em;     text-align: right;     padding-bottom: .5em; } input {     margin-left: 1em;     margin-bottom: .5em; } fieldset {...
lab3 exercise 5 html <!DOCTYPE html> <!-- Webpage HTML document for Lab 03.   Author: Amir H...
lab3 exercise 5 html <!DOCTYPE html> <!-- Webpage HTML document for Lab 03.   Author: Amir H Chinaei   For: EECS 1012, York University, Lassonde School of Engineering --> <html lang="En"> <head>   <meta charset="UTF-8">   <title> EECS1012: Lab 3 - My Kit </title>   <!-- in Ex1, add a link tag here to connect it to the css file -->   <link rel="stylesheet" type="text/css" href="myLearningKit_ex2.css">   <script src="myLearningKit_ex4.js"></script>      <!-- in Ex2, add a script tag here to connect it to the js file -->   ...
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Weather App </title> <link rel="stylesheet"...
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Weather App </title> <link rel="stylesheet" href="main.css" /> </head> <body> <div class="app-wrap"> <header> <input type="text" autocomplete="on" class="search-box" placeholder="Enter your location..." /> </header> <main> <section class= "location"> <div class="city">Hyderabad, IN</div> <div class="date">Thursday 23 July 2020</div> </section> <div class="current"> <div class="temp">25<span>°c</span></div> <div class="weather">Rainy</div> <div class="hi-low">20°c / 23°c</div> </div> </main> </div> <script src="main.js"></script> </body> </html> MAIN.js const api = { key="091ff564240e0e16c46ae680b188ca3e" base: "https://api.openweathermap.org/data/2.5" }; const searchbox = document.querySelector(".search-box"); searchbox.addEventListener("keypress", setQuery); function setQuery(evt) {...
BEFORE html <html> <head>       <link rel="stylesheet" type="text/css" href="mystyle98_d.css"> </head> <body>              <p>  
BEFORE html <html> <head>       <link rel="stylesheet" type="text/css" href="mystyle98_d.css"> </head> <body>              <p>     I'm a paragraph, what color am I ?      </p>    <ul>      <li id = "fix"> I'm a list item;what color am I? </li>        </ul> <div class = "central1"> <p class ="above"> I'm a paragraph; what color am I? </p>      <p>     I'm another paragraph, what color am I ?      </p>    <ol>      <li id = "fix1"> I'm another list item;what...
pls use the website validator.w3.org to remove all the errors in the codes <!!DOCTYPE html PUBLIC...
pls use the website validator.w3.org to remove all the errors in the codes <!!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Nchako</title> <style> p { font-family: Georgia, "Times New Roman", Times, serif; font-size: 0.95em; color: #333333; line-height: 20px; } h1 { font-family: Georgia, "Times New Roman", Times, serif; font-size: 1.4em; color: #000033; } h2 { font-family: Georgia, "Times New Roman", Times, serif; font-size: 1.2em; color: #000033; } h3 { font-family: Georgia, "Times New Roman", Times, serif; font-size: 1.1em;...
Can someone verify why my code isnt running <!DOCTYPE html> <html> <body bgcolor=aqua text=purple> <script type="text/javascript">...
Can someone verify why my code isnt running <!DOCTYPE html> <html> <body bgcolor=aqua text=purple> <script type="text/javascript"> funtion oldMacVerse(animal, sound) //Assumes: animal is the name of an animal, sound is the sound it makes //Results: displays a version of the song "Old MacDonals Had a Farm" in outputDiv { document.getElementById('outputDiv').innerHTML =    '<p>Old MacDonald had a farm, E-I-E-I-O.<br>' +    'And on that farm he had a ' + animal + ', E-I-E-I-O.<br>' +    'With a ' + sound +...
What do the following HTML statements do?                  <body>                 &
What do the following HTML statements do?                  <body>                                                                                                 <head>                                                                                                 <table>                                                                                                 <tr>                                                                                                 <td>                                                                                                
Look at the HTML below ( do NOT modify the HTML), Outer paragraph, outer list, div...
Look at the HTML below ( do NOT modify the HTML), Outer paragraph, outer list, div with 2 inner paragraphs and one inner list , create a CSS which will: Make the outer list text color blue , and make the outer (non div) paragraph blue, and the div inner list element pink also inside the div element make the first inner paragraph green, and in the div element the second paragraph blue, so that in order: blue-blue-green-blue-pink As a...
Given the HTML below ( do not modify the HTML), Outer paragraph, outer list, div with...
Given the HTML below ( do not modify the HTML), Outer paragraph, outer list, div with 2 inner paragraphs and one inner list , create a CSS which will: a) Make the outer list text color blue , and make the outer (non div) paragraph blue, and the div inner list element pink also inside the div element make the first inner paragraph green, and in the div element the second paragraph blue, so that in order: blue-blue-green-blue-pink b)As a...
Explain the following code. What language? What does it do? What is the result?                 <!DOCTYPE...
Explain the following code. What language? What does it do? What is the result?                 <!DOCTYPE teo[                                 <ELEMENT teo((stations| databases)+)>                                 <ELEMENT stations(stationName stationLocation sensors*)> <ELEMENT databases(databaseName databaseType )> <ELEMENT stationName(#PCDATA)> <ELEMENT stationLocation(#PCDATA)> <ELEMENT sensors (sensorName phenomenon)+> <ELEMENT sensorName(#PCDATA)> <ELEMENT phenomenon(#PCDATA)> <ELEMENT databaseName(#PCDATA)> <ELEMENT databaseType(#PCDATA)> <!ATTLIST stations boundingBox CDATA #required> ]>
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT