0

there are two properties for my bike method.front gear and rear gear.i want another property which will be a new property called gear ratio property which can be obtained by multiplying front and rear gear numbers.the code i have written giving continuous error.how it can be fixed.

<html>
<head>
</head>
<body>
<script>
function write(){
var bicycle={
   price:20000,
   model:"raleigh",
  front_gear:3,
   rear_gear:7,
    gear_ratio:function(){
      ratio:this.front_gear*this.rear_gear
       }
      }
      document.write("this is a "+bicycle.gear_ratio.ratio+" speed bike");
      }
      window.onload=write;
</script>
</body>
</html>

Edited by pritaeas: Moved to Js.

2
Contributors
1
Reply
13
Views
3 Years
Discussion Span
Last Post by GliderPilot
0

You're combining two different methods of doing this which will fail, need to choose one or the other, try this (Sorry for these not being in code boxes, my work PC doesn't like DaniWeb):

Change line 13 to:
return this.front_gear * this.rear_gear;

Change line 16 to:
document.write("this is a " + bicycle.gear_ratio + " speed bike");

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.