對於課堂作業,我們需要製作一個有趣的網站,突出JavaScript的隨機功能。我的網站是一個喲媽媽笑話生成器,所以每次刷新頁面時都會出現一個新的笑話。然而,我的代碼不工作,我似乎無法弄清楚爲什麼它不是。我是初學者,所以任何幫助將不勝感激! :)從數組中生成隨機句子Javascript
這裏是我的代碼:
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
smooth();
}
function draw() {
background (255, 255, 255);
}
function getRandomSentence() {
var index= Math.floor(Math.random() * (maxSentences - 1));
return sentences[index];
}
var sentences= [
'so fat not even Dora can explore her',
'so fat I swerved to miss her and ran out of gas',
'so smelly she put on Right Guard and it went left',
'so fat she hasn’t got cellulite, she’s got celluheavy',
'so fat she don’t need no internet – she’s already world wide',
'so hair her armpits look like Don King in a headlock',
'so classless she could be a Marxist utopia',
'so fat she can hear bacon cooking in Canada',
'so fat she won 「The Bachelor」 because she all those other bitches',
'so stupid she believes everything that Brian Williams says',
'so ugly she scared off Flavor Flav',
'is like Domino’s Pizza, one call does it all',
'is twice the man you are',
'is like Bazooka Joe, 5 cents a blow',
'is like an ATM, open 24/7',
'is like a championship ring, everybody puts a finger in her'
],
maxSentences = sentences.length;
,這裏是我的html:
<html>
<head>
<title>new tab</title>
<meta charset="utf-8">
<script src='./js/jquery-2.1.1.min.js' type='text/javascript'></script>
<script src='./js/p5.min.js' type='text/javascript'></script>
<script src='./js/sketch.js' type='text/javascript'></script>
<script src='./js/main.js' type='text/javascript'></script>
<link href='./css/reset.css' media='all' rel='stylesheet' type='text/css' />
<link href='./css/main.css' media='all' rel='stylesheet' type='text/css' />
</head>
<body>
</body>
</html>
你回來了一個隨機的句子,然後呢?文本如何繪製到頁面上? – Nayuki
你是什麼意思'不工作'?在這裏發佈您的HTML。 – CurseStacker
@CurseStacker這裏是我的html – musst248