Ich kann Aufforderungen zu Popup auf meiner Website bekommen, aber wenn ich console.log oder Rückgabe in Javascript es nicht auf meiner Website ausdrucken.Warum kann ich mein Javascript (Rock, Paper, Scissors Spiel) nicht bekommen, um die Ausgaben auf meiner Website zu zeigen?
Meine Website ist www.caelanbacon.com
Hier ist mein Code:
<!doctype html>
<html>
<head>
<title>Caelan Bacon</title>
</head>
<body>
<script type="text/javascript">
var userChoice = prompt ("rock, paper, or scissors?");
while (userChoice !== "rock" && userChoice !== "paper" && userChoice !== "scissors") {
console.log("Invalid submission.");
userChoice = prompt("Try again?");
}
var computerChoice = Math.random();
if (computerChoice < 0.34) {
console.log = "rock";
} else if(computerChoice < 0.66) {
console.log = "paper";
} else {
console.log = "scissors";
}
var choice1 = userChoice;
var choice2 = computerChoice;
console.log("You chose " + choice1);
console.log("System: " + choice2);
var compare = function (choice1, choice2) {//start function
if (choice1 === choice2) {
return "The result is a tie!";
} else if (choice1 === "rock") {
if (choice2 === "scissors") {
return "rock wins";
} else {
return "paper wins";
}
} else if (choice1 === "paper") {
if (choice2 === "rock") {
return "paper wins";
} else {
return "scissors wins";
}
} else {
if (choice2 === "paper") {
return "scissors wins";
} else {
return "rock wins";
}
}
}//end function
compare(userChoice,computerChoice);
</script>
<footer>
© CaelanBacon.com 2016. All rights reserved.
</footer>
</body>
</html>
'console.log' schreibt nicht auf Ihre Seite. Es schreibt auf Ihre Konsole. Drücke F12, um deine Konsole zu öffnen. Ich schlage vor, Sie damit vertraut zu machen, weil es das wertvollste Debugging-Tool ist, das Sie haben. –
@MikeC haben control + shift + j seit Jahren verwendet, wusste nicht, dass es eine kürzere Abkürzung gab, danke :) – juvian
@Mike C - Ich bin verwirrt. Ich bin auf Mac (MacBook Pro OSX) und F12 ist ein Sound-Key, und die Funktion Teil davon geht nur zum Armaturenbrett ... Was fehlt mir? Ich fühle mich dumm. – Bacon