Question

Create an object that contains the 2 random numbers generated from JavaScript random function. The object...

Create an object that contains the 2 random numbers generated from JavaScript random function. The object should also contain a function that finds the bigger one of the two numbers. Display the 2 random numbers in the attached html file, then display the larger of the two with appropriate label. Here is my HTML code

<!DOCTYPE html>
<html>
<head>
    <title>midterm exam</title>
    <link rel="stylesheet" href="css/q1.css" />
</head>
<body>
    <section id="page">
      <h1>Question 1</h1>
    
      <section id="whitespace"></section>
    </section>
    <script src="js/q1.js"></script>
</body>
</html>

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any problem with the code feel free to comment.

JavaScript Program

var numObj = {
//generating radome number between 0-100
number1 : Math.floor(Math.random()*100),
number2 : Math.floor(Math.random()*100),
  
//finding the bigger number
biggerOne(){
if(this.number1 > this.number2)
return this.number1;
else
return this.number2;
}
};

//printing the output
document.write('Number 1: '+numObj.number1+'<br>');
document.write('Number 2: '+numObj.number2+'<br>');
document.write('Bigger Number: '+numObj.biggerOne());

Output

Add a comment
Know the answer?
Add Answer to:
Create an object that contains the 2 random numbers generated from JavaScript random function. The object...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT