Skip to content

Instantly share code, notes, and snippets.

@lucywoodman
Last active April 4, 2022 07:19
Show Gist options
  • Save lucywoodman/8ed41d5a01ffda4f58ffc3f81c214b53 to your computer and use it in GitHub Desktop.
Save lucywoodman/8ed41d5a01ffda4f58ffc3f81c214b53 to your computer and use it in GitHub Desktop.
Kids lunch generator
{
"scripts": [],
"styles": []
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title></title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Kid Lunch Generator</h1>
<main></main>
<script type="text/javascript" src="kidLunchGenerator.js"></script>
</body>
</html>
const protein = [
'cooked chicken',
'ham',
'cocktail sausages',
'boiled egg'
];
const carbs = [
'wrap',
'bread',
'crackers',
'potatoes'
];
const veggies = [
'cucumber',
'cherry tomatoes',
'sugar snap peas',
'sweetcorn',
'carrots',
'bell peppers'
];
const fruit = [
'strawberries',
'blueberries',
'raspberries',
'satsuma',
'banana',
'apple',
'pear',
'melon'
];
const fat = [
'olives',
'avocado',
'seeds',
'olive/coconut oil',
'mayonnaise'
];
const treat = [
'cake',
'biscuit/cookie',
'crisps',
'dried fruit',
'flapjack'
];
const randomProtein = Math.floor(Math.random() * protein.length);
const selectProtein = protein[randomProtein];
const randomCarbs = Math.floor(Math.random() * carbs.length);
const selectCarbs = carbs[randomCarbs];
const randomVeggies = Math.floor(Math.random() * veggies.length);
const selectVeggies = veggies[randomVeggies];
const randomFruit = Math.floor(Math.random() * fruit.length);
const selectFruit = fruit[randomFruit];
const randomFat = Math.floor(Math.random() * fat.length);
const selectFat = fat[randomFat];
const randomTreat = Math.floor(Math.random() * treat.length);
const selectTreat = treat[randomTreat];
const fullList = [
selectProtein, selectCarbs, selectVeggies, selectFruit, selectFat, selectTreat
]
function createPrettyList(arr) {
let items = '';
for (let i = 0; i < arr.length; i++) {
items += `<li>${arr[i]}</li>`;
}
return items;
}
document.querySelector('main').innerHTML = `
<ul>
${createPrettyList(fullList)}
</ul>
`;
body {
font-family: Helvetica, sans-serif;
font-size: 24px;
margin: auto;
max-width: 50%;
background-color: lightcoral;
text-align: center;
}
h1 {
color: snow;
padding: 20px 0 20px 30px;
}
ul {
list-style: none;
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}
li {
background-color: snow;
border-radius: 10px;
padding: 30px 35px;
margin: 20px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment