dhmyers82 Posted February 1, 2015 Share Posted February 1, 2015 Chapter 2 homework is coded. It works and that is the main thing, but I dont just want the grade, I want want to learn php and be proficent at it. Is there anything that looks wrong, Variable names, lack off comments, things out of place. All advice is welcome. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "html://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Temperature Conversion</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <h1>Fahrenheit to Celsius Conversions</h1> <article> <?php $degFahrenheit = 0; function degreeConverter ($degFahrenheit) { //Function converts F* to C* $degCelsius = (($degFahrenheit - 32) * 5/9); $returnCelsius = round ($degCelsius, 1); return $returnCelsius; } do {//begining of loop $convertCelsius = degreeConverter($degFahrenheit); echo "<p>$degFahrenheit degrees Fahrenheit = $convertCelsius degrees Celsius.</p>"; ++degFahrenheit; } while ($degFahrenheit <= 100);//end of loop ?> </article> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/294302-advice-needed/ Share on other sites More sharing options...
Strider64 Posted February 1, 2015 Share Posted February 1, 2015 You sure it works? do {//begining of loop $convertCelsius = degreeConverter($degFahrenheit); echo "<p>$degFahrenheit degrees Fahrenheit = $convertCelsius degrees Celsius.</p>"; ++degFahrenheit; // Cough Cough.... } while ($degFahrenheit <= 100);//end of loop Quote Link to comment https://forums.phpfreaks.com/topic/294302-advice-needed/#findComment-1504508 Share on other sites More sharing options...
dhmyers82 Posted February 1, 2015 Author Share Posted February 1, 2015 $$$$$$$$$$ yeah, I found that one also. Does eveything else look ok? Naming is what I struggle with alot. I never know what to name things to keep everything straight and to the point. Quote Link to comment https://forums.phpfreaks.com/topic/294302-advice-needed/#findComment-1504509 Share on other sites More sharing options...
Solution Strider64 Posted February 1, 2015 Solution Share Posted February 1, 2015 (edited) There's really nothing wrong in how you did it for it works and that is all that matters.   However, this is how I would do it: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "html://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Temperature Conversion</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <h1>Fahrenheit to Celsius Conversions</h1> <article> <?php $fahrenheit = 0; /* Convert Fahrenheit to Celsius */ function fahrenheitToCelsius($fahrenheit) { return round( ($fahrenheit - 32) * 5/9, 1); } do {//begining of loop $celsius= fahrenheitToCelsius($fahrenheit); echo "<p>$fahrenheit° F = $celsius° C.</p>"; ++$fahrenheit; } while ($fahrenheit <= 100);//end of loop ?> </article> </body> </html> However, I sure everyone else here would do it a little bit differently. Edited February 1, 2015 by Strider64 1 Quote Link to comment https://forums.phpfreaks.com/topic/294302-advice-needed/#findComment-1504510 Share on other sites More sharing options...
dhmyers82 Posted February 1, 2015 Author Share Posted February 1, 2015 Thats where I want to get to. Its much simpler and more streamlined. Thank you for posting. Quote Link to comment https://forums.phpfreaks.com/topic/294302-advice-needed/#findComment-1504511 Share on other sites More sharing options...
CroNiX Posted February 1, 2015 Share Posted February 1, 2015 I'd use an HTML5 doctype. XHTML1 is so old and outdated. <article> is also an HTML5 element, so it would be best to use the correct doctype. 1 Quote Link to comment https://forums.phpfreaks.com/topic/294302-advice-needed/#findComment-1504519 Share on other sites More sharing options...
dhmyers82 Posted February 5, 2015 Author Share Posted February 5, 2015 Thank you. I find it stupid that the book has us using xhtml, and <div>! i was taught html 5 as you can see by my tags. I just haven't converted the head over yet. Quote Link to comment https://forums.phpfreaks.com/topic/294302-advice-needed/#findComment-1504933 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.