Jump to content

This calculator thing doesn't work, help me Jacques you're my only hope


siby

Recommended Posts

Hi Jacques1,

 

I have written this code for a biorhythm calculator but I can't figure out why it doesn't work, would you be able to take a look and see if you can find the problem?

It would be greatly appreciated, thank you.

<html> 
<head>

<script>
  var months = 'janfebmaraprmayjunjulaugsepoctnovdec';
  var PI = 3.14159265358979323846; 
  var msPerDay = 1000*60*60*24;
  var interllectualCycle = 33;
  var emotionalCycle = 28;
  var physicalCycle = 23;  
    

  var birthYear =  parseInt(prompt( 'Enter year of birth as a 4 digit integer' ));

  var birthMonth = prompt( 'Enter name of month of birth' );
  
//request month of birth

  var pos = months.indexOf(birthMonth.substring(0, 3) 
   .toLowerCase() );
  var posMonth = pos / 3;
  
         //alert( 'Month number: ' + pos );

//convert month to number
	  
  var numberInString = posMonth;

  var numberMonth = new Number(numberInString);

        // alert(numberMonth);


  var birthDay = parseInt (prompt('Enter day of birth as an integer')); 

//enters birthdate into string

  var userBirthday = new Date(birthYear, numberMonth, birthDay);
       //alert ('' + userBirthday);
	
//date object created for current date

  var currentDate = new Date();
      //  alert ('' +currentDate)
  
//creating users age in milliseconds 

  var msSinceBirth = currentDate.getTime()- userBirthday.getTime() ;
   // alert ('' +msSinceBirth);
  
//creating users age in days 
 
   var userMsDays  = Math.floor(msSinceBirth / msPerDay);
  
     //document.write ('' +  userMsDays); 
		

   var bioEnergy = (userMsDays * (2 * PI ) / interllectualCycle);
   var bioEmot = (userMsDays * (2 * PI) / emotionalCycle);
   var bioPhy = (userMsDays * (2 * PI) / physicalCycle);
   
//Biorhythm energy levels output   
  document.write('You have been alive' + userMsDays + 'days');
  document.write('<h1>"Your biorhythm energy levels are :-"</h1>');
  document.write('<ul>');  
  document.write('<li><font color="green">intellectual:</font></li>' + [Math.sin(bioEnergy).toFixed(1)]); 
  document.write('<li><font color="red">emotional:</font></li>' + '' +  [Math.sin(bioEmot).toFixed(1)]); 
  document.write('<li><font color="blue">physical:</font></li>' + [Math.sin(bioPhy).toFixed(1)]);
  document.write('</ul>');
	
 

</script>
 
</head> 
         
</html>
Link to comment
Share on other sites

I'm sorry, I'm new to this website and I didn't know you couldn't post on others threads.

 

I don't know what the problem is, which is why I can't explain it. I was under the impression you knew a great deal about coding and could help me out by identifying the problem, as I am new to coding and am having trouble. Thanks for your time though.

Link to comment
Share on other sites

What kind of trouble? Does your PC catch fire when you run the script? Do you get an error message? A specific unexpected result for a specific input?

 

I know this is hard to understand, but we're not sitting in front of your screen, and we cannot read your mind. All you've provided is a wall of code and the vague information that you think there's something wrong with it. What are we supposed to do now?

 

Be specific.

Link to comment
Share on other sites

Well when I try opening it in a web browser, it doesn't display the pop up's with text boxes which I thought I had gotten it to do. See when you open it in firefox or chrome it's supposed to ask for your year of birth then month then date, but it just opens a page with the code.

Link to comment
Share on other sites

Oh wow, thank you so much, I can't believe it was that simple! 

 

It doesn't give me the correct answer when I type the information in, but I'll try and figure that out.

 

thank you thank you thank you!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.