Hi, im facing the first challenge of js libraries : this project im setting js first but codepen tell me syntax error. hope you can give me a hint
Here’s my project
in codepen JS editor press the down arrow and click analyze
also looks like you are missing a check condition in the second for loop in getQuote function.
unction getQuote= (arr) => {
for (let i = 0; i<arr.length; i++)
for (let y = Math.floor(Math.random() * arr.length)){ <------- HERE
(while i <=y){
let result = '';
result= result + arr[y];
return result
}
}
}
Ok, i not so much good in grammary, anyway can i ask you how to set the react environment? do i have to change from js to babel? yesterday i did so, but even with the reactDom.render it didnt seem work.
Can someone help me? i have done this script:
var quotesData = [ "La vita, se vissuta bene, è lunga abbastanza.", "Ieri è andato. Domani non è ancora arrivato. Abbiamo solo oggi. Cominciamo.", "Più conosci te stesso, più comprendi la vita, più apprezzi il tuo tempo.", "Ogni secondo ha un valore infinito."];
var tuttiGliAutori = ["Seneca", "Madre Teresa", "Maxime Lagacé ", "Johann Wolfgang von Goethe "];
var nextQuote = '';
var nextAuthor = '';
var y = Math.floor(Math.random() * quotesData.length);
console.log(y); // yes
var z = Math.floor(Math.random() *tuttiGliAutori.length);;
const onClickFunction = () => { document.getElementById("p1").innerHTML = quotesData[y];}
const onClickFunction2 = () => {document.getElementById("p2").innerHTML = tuttiGliAutori[y]}
this is the html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="loscript.js"></script>
</head>
<body>
<div>
<div>
<h1 id="p1">Quote</h1>
<h5 id = "p2">Author</h5>
<button onclick="onClickFunction(); onClickFunction2();">New Quote</button>
</div>
</div>
</body>
</html>
the h1 and h5 value dosent change on click, hope you can give me a hint!
My last code seems it works, i only want to ask you: how can i repeat at infinite my functions that start onclick in my button? using the infinite loop my browser crash!
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.