<!DOCTYPE html>
<html lang="pl">
<head>
</head>
<body>
<script>
var dictionary = [];
var test = [];
var word1 = {
baseWord: "angry",
translation: "zły",
baseKey: "pl",
targetKey: "en"
};
add (word1);
var word2 = {
baseWord: "happy",
translation: "szczęśliwy",
baseKey: "pl",
targetKey: "en"
};
add (word2);
var word3 = {
baseWord: "hate",
translation: "nienawiść",
baseKey: "pl",
targetKey: "en"
};
add (word3);
var word4 = {
baseWord: "bored",
translation: "znudzony",
baseKey: "pl",
targetKey: "en"
};
add (word4);
var word5 = {
baseWord: "excited",
translation: "podniecony",
baseKey: "pl",
targetKey: "en"
};
add (word5);
var word6 = {
baseWord: "love",
translation: "miłość",
baseKey: "pl",
targetKey: "en"
};
add (word6);
var word7 = {
baseWord: "sad",
translation: "smutny",
baseKey: "pl",
targetKey: "en"
};
add (word7);
var word8 = {
baseWord: "tired",
translation: "zmęczony",
baseKey: "pl",
targetKey: "en"
};
add (word8);
var word9 = {
baseWord: "scared",
translation: "przestraszony",
baseKey: "pl",
targetKey: "en"
};
add (word9);
var word10 = {
baseWord: "worried",
translation: "zmartwiony",
baseKey: "pl",
targetKey: "en"
};
add (word10);
remove(word9);
function add(word){
dictionary.push(word);
//test.push(word);
}
function remove (samolot){
dictionary.forEach(function (el,ind) {
if(el===samolot){
dictionary.splice(ind,1);
}
});
}
function getRandomWordFromDictionary() {
var randomKey = Math.floor(Math.random() * (dictionary.length));
return dictionary[randomKey];
}
console.log(getRandomWordFromDictionary())
console.log(getRandomWordFromDictionary())
console.log(getRandomWordFromDictionary())
console.log(getRandomWordFromDictionary())
console.log(getRandomWordFromDictionary())
console.log(getRandomWordFromDictionary())
console.log(getRandomWordFromDictionary())
console.log(getRandomWordFromDictionary())
console.log(getRandomWordFromDictionary())
console.log(getRandomWordFromDictionary())
</script>
</body>
</html>
to moj kod, jak zrobic zeby wynik losowania sie nie powtórzył....najlepiej jakby ktos pokazał, jak powinien wygladać kod oparty na moim kodzie . Dziekuje za pomoc...;)