Question

Javascript Let's say there's 40 shapes in a bag, half of them are circles and the...

Javascript

Let's say there's 40 shapes in a bag, half of them are circles and the other half are squares. Using an if/else statement nested in a for loop, how do I use math.random to draw either a square or a circle?

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

> for(var í 0;i<10; i++)( var rand -Math.floor ((Math.random) if(rand 1) 2) 1); console.log(Circle) elset console.log( Squ

\color{blue}\underline{Code:}

for(var i = 0;i<10;i++){
   var rand = Math.floor((Math.random() * 2) + 1);
   if(rand == 1){
      console.log("Circle");
   }
   else{
      console.log("Square");
   }
}

\color{red}Please\; upvote\;the \;solution \;if \;it \;helped.\;Thanks!?

Add a comment
Know the answer?
Add Answer to:
Javascript Let's say there's 40 shapes in a bag, half of them are circles and the...
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
  • Write a program in Python that will: Here are following requirements to completing Menu shapes: 1....

    Write a program in Python that will: Here are following requirements to completing Menu shapes: 1. Create a "MENU" with 4 - 5 options have the user click the option and thereafter ask the user to enter the amount of stars from 1 - 50. From there your "for loop" will create the shape. Menu options need to be: 1. Filled Triangle 2. filled Square 3. This can be any shape such as a Square, circle, a different angle of...

  • Given a double variable named x that has been declared and given a value, let's use a binary search technique to assign...

    Given a double variable named x that has been declared and given a value, let's use a binary search technique to assign an estimate of its square root to another double variable, root that has also been declared. Let's assume that x's value is greater than 1.0 -- that will simplify things a bit. Here's the general idea: Since x>1, we know its square root must be between 1 and x itself. So declare two other variables of type double...

  • How much does a sleeping beg cost? Let's say you want a sleeping bag that should...

    How much does a sleeping beg cost? Let's say you want a sleeping bag that should keep you warm in temperatures frem range is given below. Assume that the population of x values has an approximately normal distribution. i 20°F to 45'F. A random sample of prices (8) for sieeping bags in ehes temperature 45 55 90 120 0 90 30 23 100110 10595 105 60110 12095 90 60 () Use a cakculator with -$ 81.15 -$ 29.72 mean and...

  • For this lab you will write a small program that prints a few "shapes" using asterisks....

    For this lab you will write a small program that prints a few "shapes" using asterisks. Your program will prompt the user to select a shape by entering a number (square or triangle for B grade, add the zig- zag for the A grade). It will then prompt for the size, and then if a square or triangle is selected it will prompt for "not filled" or "filled", and if azig-zag is selected it will prompt for the number of...

  • so the assigment given is to draw a CNC machine figure with atleast 40 lines of...

    so the assigment given is to draw a CNC machine figure with atleast 40 lines of g-code (USING ONLY G91, G90, G0,G1,G2,G3,G70,G71,G90)! DO NOT USE R, T01 OR M0 Only the simple (G91, G90, G0,G1,G2,G3,G70,G71,G90) codes are allowed to be used NO DRILLING CODES!!!!!!!!! Use basic shapes like triangles and rectangles and the sketch MUST CONTAIN A CIRCLE!!!!!!!!!!!!!! the dimension boundaries are x=3in and y=3in It must contain at least one circle and must be 40 blocks please provide me...

  • Modify the NervousShapes program so that it displays equilateral triangles as well as circles and rectangles....

    Modify the NervousShapes program so that it displays equilateral triangles as well as circles and rectangles. You will need to define a Triangle class containing a single instance variable, representing the length of one of the triangle’s sides. Have the program create circles, rectangles, and triangles with equal probability. Circle and Rectangle is done, please comment on your methods so i can understand */ package NervousShapes; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*; import javax.swing.event.*; public class...

  • WEB230 - JavaScript 1 Assignment 6a Use Events and DOM manipulation to create a playable Tic...

    WEB230 - JavaScript 1 Assignment 6a Use Events and DOM manipulation to create a playable Tic Tac Toe game. Do the following using JavaScript. Do not modify the HTML file. When you see this symbol: save and refresh the browser (this should happen automatically if you are using Brackets with Live Preview), then check your code to make sure it is working before you proceed. 1. Create two variables called "playerX" and "playero". Set them to the DOM element with...

  • Write a C program that does the following: • Displays a menu (similar to what you...

    Write a C program that does the following: • Displays a menu (similar to what you see in a Bank ATM machine) that prompts the user to enter a single character S or D or Q and then prints a shape of Square, Diamond (with selected height and selected symbol), or Quits if user entered Q. Apart from these 2 other shapes, add a new shape of your choice for any related character. • Program then prompts the user to...

  • Part # 1 How much does a sleeping bag cost? Let's say you want a sleeping...

    Part # 1 How much does a sleeping bag cost? Let's say you want a sleeping bag that should keep you warm in temperatures from 20°F to 45°F. A random sample of prices ($) for sleeping bags in this temperature range is given below. Assume that the population of x values has an approximately normal distribution. 80 115 110 55 40 70 30 23 100 110 105 95 105 60 110 120 95 90 60 70 (a) Use a calculator...

  • import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow...

    import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow for simple graphical drawing on a canvas. * This is a modification of the general purpose Canvas, specially made for * the BlueJ "shapes" example. * * @author: Bruce Quig * @author: Michael Kolling (mik) * Minor changes to canvas dimensions by William Smith 6/4/2012 * * @version: 1.6 (shapes) */ public class Canvas { // Note: The implementation of this class (specifically the...

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
ADVERTISEMENT