Ich würde gerne wissen, wie mein Code auf einer Webseite angezeigt werden könnte, anstatt in Alarmfeldern angezeigt zu werden, wie mache ich das. Ich verstehe, dass Ids ect benötigt werden, aber ich bin ein wenig verwirrt, wo ich anfangen soll. Jede Hilfe wäre gut. Vielen Dank!Wie integriere ich Java Script in HTML?
<!DOCTYPE html>
<html>
<script>
//Set of variables
var nameCheck = /^[a-zA-Z\s]+$/;
//eliminates anything not relevant
var numberCheck = /^[0-9\.]+$/;
//eliminates anything not relevant
var totHours = 0;
//adds total gaming hours on one day
var dayHours = 0;
//how many on one such day set in i from 1-7
var averHours = 0;
//stores the average by dividing by the tothours by 7
var mostPerDay = 0;
//calculates day with most gamed
var mostOnDay = 0;
//Most hours on ONE day
var moreDays = " ";
//adds an s to the end of days if more than one
var mpd = 0;
//most per day
var ah = 0;
//average hours
var th = 0;
//total hours
var name = prompt("What is your name?");
//asks users name
//Make sure user inputs a name that includes letters and or spaces
while (name == "null" || isNaN(name) == false || !name.match(nameCheck)){
\t alert("Invalid Name!");
\t name = prompt("What is your name?");
}
//Greets the user by name
alert("Hello " + name);
//Ask how many hours gamed on a day
for (var i = 1; i <= 7; i++){
\t dayHours = prompt("How many hours have you gamed on day " + i + "?")
//Reask the question if the user inputs an invald answer
\t while (dayHours == null || isNaN(dayHours) || dayHours > 24 || !dayHours.match(numberCheck) || dayHours < 0){
\t \t alert("Incorrect! No letters or symbols, and make sure your input is under 24");
\t \t dayHours = prompt("How many hours have you gamed on day " + i + "?")
\t }
//Adds to total hours
totHours += Number(dayHours)
//Calculates days with most hours gamed
if (mostPerDay > dayHours){
}
else if (mostPerDay < dayHours){
\t mostPerDay = Number(dayHours);
\t mostOnDay = i;
}
else if (mostPerDay = dayHours){
\t mostOnDay += " and " + i;
\t mostPerDay = Number(dayHours);
}
}
//Adds 's' to the statistics if more than one day
if (isNaN(mostOnDay) == true){
\t moreDays = "s ";
}
//Divides the total hours by 7 to get average over those 7 days
aver = (totHours/7);
//Calculates and rounds to the value of 1
th = totHours.toFixed(1);
ah = aver.toFixed(2);
mpd = mostPerDay.toFixed(1);
//States calculated statistics
alert("\nTotal gaming hours this week " + th + "\nAverage gaming hours this week " + ah + "\nMost on one day" + moreDays + mostOnDay + " for " + mpd + " hours.");
//Comments on average hours per day gamed
if (averHours <= 2){
alert("Healthy amount of gaming this week")
}
else if (averHours <= 24){
\t alert("Unhealthy amount of gaming this week")
}
</script>
</html>