Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/School-Work / School Work/updateLottery.js |
| Date | Not specified in source |
| Repository | Janady13/School-Work |
| Revision | 4a666c890caf7c43c47d0572dbcc287373c7a78e |
| Branch | main |
| Path or archive member | School Work/updateLottery.js |
| Original SHA-256 | ca153e3fde791e4cde069a57388b797438d41114807ff88a3432cf7d0a7921a8 |
| Git blob SHA | 1777fad6fc2ff49b58115e2e8676de696a9488ed |
| Reading-copy SHA-256 | ca153e3fde791e4cde069a57388b797438d41114807ff88a3432cf7d0a7921a8 |
Recovered source transcript
Download complete source text ↓37 lines · 1.1 KB
const minNum =1;
const maxNum =100;
const numPicks = 5;
function generateNumbers(min, max, num) {
const numbers = []; //array
while (numbers.length < num) { //method
const randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
if (!numbers.includes(randomNum)) {
numbers.push(randomNum);
}
}
return numbers;
}
function playLottery(myPicks){
const winningNumbers = generateNumbers(minNum,maxNum,numPicks);
const matchedNumbers = myPicks.filter( num => winningNumbers.includes(num))
const numMatches = matchedNumbers.length;
let message = `Winning numbers: ${winningNumbers.join(", ")}\n`;
if (numMatches === numPicks) {
message += `Congratulations! You have won the jackpot!`;
} else if (numMatches > 0) {
message += `You matched ${numMatches} number(s): ${matchedNumbers.join(", ")}`;
} else {
message += `Sorry, you did not win this time. Better luck next time!`;
}
return message;
}
// Example usage
const myPicks = [7, 12, 23, 34, 45];
const result = playLottery(myPicks);
console.log(result);