#Signal-to-Noise ratio
Signal-to-Noise ratio
#Signal-to-Noise ratio
Signal-to-Noise ratio
#Signal-to-Noise ratio
Take this with a grain of salt, I realize your teacher might actually have made that a requirement. Generally, comments should not be used to describe what the code is doing, as the code itself does a pretty good job of doing that itself. Comments should be used to explain why your code is doing something, in cases where you are doing something unusual or that is not obviously clear.
For example, these comments are not useful:
<?php
session_start(); //start use of sessions on this document
//This is a function that gets the result of the Resultval session, if not set it returns 0
function getResIfSet() {
if (isset($_SESSION["Resultval"])) {
echo $_SESSION["Resultval"];
} else {
echo 0;
}
}
?>
You could simply instead write function getResultIfSet()
and the code would be self-explaining. Here is another example where the comments are not useful, and just make it harder to read:
//get the input from the form index.php sent to this document.. if its empty.. set an error (bellow)
function getInput() {
//if input session isnt set to anything...
if (!empty($_POST["Input"]) && isset($_POST["Input"])) {
return $_POST['Input']; //return the value if it is set
} else {
//if not..
setResult("Error: Input is empty!"); //set the result to the error message
setBox("error"); //set the box type to error (red border)
returnToStart(); //and finally return the user back to index.php
}
}
Instead this would read better:
function getInput() {
if (!empty($_POST["Input"]) && isset($_POST["Input"])) {
return $_POST['Input'];
} else {
setResult("Error: Input is empty!");
setBox("error");
returnToStart();
}
}
You did make some comments that were helpful, where the code itself was not clear why you are doing something unusual looking:
//if the result equals 1337 (Easter egg2)
if (res == "1337") {
$(".mainwindow").animate({top: '-2000px'}, 2000); //Make .mainwindow float far up
$("#elite").fadeIn(1000); //Fade in the #elite (img)
$("#elite_text").fadeIn(3000); //Fade in the #elite_text (paragaph)
}
And here also:
//This is the "OM NOM NOM" easter egg.. if the #log_box is expanded 5 times it turns it into a face!
if (clicks === 5) {
$(".mainwindow").fadeOut(5000);
$("h1").html("0 0");
$("#log_box").html("'OM NOM NOM!'<br><br><br><br><br><br><br>");
$("form").html(" ");
$(".box").css("display", "none");
} else {
//if clicks isnt 5.. increase it each time the #log_box expands
clicks++;
}
As for the code itself, I think it looks good and well written, hopefully someone more experienced will find other things to say about it.