Total members 11894 |It is currently Sat Nov 23, 2024 6:53 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





javascript code
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>BMI calculator</title>
<script type="text/javascript">
/* These are the 2 scripts I have made the first one does a whole # between the 2 parameters.
The secound does the first number to the power of the secound */

var random = function(least,most){
return Math.floor(Math.random()*most + least);
};

var power = function(base,exponent){
var loop=1;
var den = 1;
if(exponent===0){
return 1;
}
else if(exponent>0){
for(c=0;c<exponent;c++){
loop=base*loop;
}
return loop;
}
else if(exponent<0){
for(c=0;c<(exponent*-1);c++){
den=base*den;
}
loop=1/den;
return loop;
}
};
var cal2=function(){
var weight=document.getElementById("weight").value;
console.log(weight);
var feet=document.getElementById("feet").value;
console.log(feet)
var inches =document.getElementById("inches").value;
console.log(inches);
var bmi =(weight)/(((feet)*12+(inches))*((feet)*12+(inches)))*703
console.log(bmi)
console.log((100)/((5*12+2)*(5*12+2))*703)
}
</script>
</head>
<body>
<b>Weight</b><br>
<input type="text" value="" id="weight" onFocus="this.select()" size="2"/>Pounds<br>
<b>Height</b><br>
<input type="text" value="" id="feet" onFocus="this.select()" size="2"/>Feet
<input type=text" value="" id="inches" onFocus"this.select()" size="2"/>Inches
<br><input type="button" value="submit" onClick="cal2()"
</body>
</html>





Author:
Newbie
User avatar Posts: 6
Have thanks: 0 time

what is the problem exactly ?

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

I am trying to create a program where you enter in height and weight and it prints put bmi. It is not that it is printing nothing just that the # is wrong.

BMI calculation is (pounds/height in inches * height in inches)*703


Author:
Newbie
User avatar Posts: 6
Have thanks: 0 time

I understand that your code is not printing the output , please check this updated snippet :
Code:

<!DOCTYPE html>
<
html>
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<
title>BMI calculator</title>
<
script type="text/javascript">
/* These are the 2 scripts I have made the first one does a whole # between the 2 parameters.
The secound does the first number to the power of the secound */

var random = function(least,most){
return 
Math.floor(Math.random()*most least);
};

var 
power = function(base,exponent){
   var 
loop=1;
   var 
den 1;
   if(
exponent===0){
      return 
1;
   }
   else if(
exponent>0){
      for(
c=0;c<exponent;c++){
      
loop=base*loop;   
      }
      return 
loop;
   }
   else if(
exponent<0){
         for(
c=0;c<(exponent*-1);c++){
      
den=base*den;   
      }
      
loop=1/den;
      return 
loop;
   }
};
var 
cal2=function(){
 
var 
weight=document.getElementById("weight").value;
console.log(weight);
 
var 
feet=document.getElementById("feet").value;
console.log(feet)
var 
inches =document.getElementById("inches").value;
console.log(inches);
var 
bmi =(weight)/(((feet)*12+(inches))*((feet)*12+(inches)))*703
document
.getElementById("outdiv").innerHTML="bmi value equals: "+bmi;
console.log(bmi)
console.log((100)/((5*12+2)*(5*12+2))*703)
}
</script>
</head>
<body>
<b>Weight</b><br>
<input type="text" value="" id="weight" onFocus="this.select()" size="2"/>Pounds<br>
<b>Height</b><br>
<input type="text" value="" id="feet" onFocus="this.select()" size="2"/>Feet
<input type=text" value="" id="inches" onFocus"this.select()" size="2"/>Inches
<br><input type="button" value="submit" onClick="cal2()"/>
<br/><div id="outdiv" />
</body>
</html>


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 4 posts ] 

  Related Posts  to : Problem with BMI calcualtor in JavaScript
 JavaScript fade out problem     -  
 I'm having a problem creating a Javascript form. Whats wrong     -  
 MVC problem....     -  
 i have problem     -  
 Skymiles [3.04] little? problem     -  
 Paging problem in php     -  
 JSTL URI problem     -  
 Window 7 problem....     -  
 Windows problem!!!     -  
 Problem with skymiles_red     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com