Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>
- What to eat for dinner?
- </title>
- <link rel="stylesheet" type="text/css" href="a9pc_styles.css">
- <style>
- /* this style just aligns answers vertically */
- .choice { display: block; }
- </style>
- </head>
- <body>
- <script>
- // <![CDATA[
- /************************************************************************************
- This is how you enter the weights for each possible question / answer / result:
- q: question #
- a: answer #
- r: result #
- for example, q1a2r3 determines how r3's score is affected if a2 is picked for q1
- var weights = [
- [[q1a1r1, q1a1r2, q1a1r3, ... q1a1r?], [q1a2r1, q1a2r2, ...], [q1a?s1, ...]],
- [[q2a1r1, q2a1r2, ...], [q2a2r1, ...], [q2a?r1, ...]],
- ...
- [[q?a1r1, q?a1r2, ...], [q?a2r1, ...], [q?a?r1, ...]]
- ]
- *************************************************************************************/
- /****************
- WEIGHTS GO BELOW
- *****************/
- var weights = [
- // Question 1
- [ [ 10 , 3 , 5 , 2 , 2 , 0 ] , [ 2 , 10 , 5 , 2 , 2 , 2 ] , [ 3 , 2 , 5 , 5 , 10 , 1 ] , [ 5 , 3 , 10 , 1 , 1 , 2 ] ] ,
- // Question 2
- [ [ 12 , 9 , 13 , 0 , 8 , -5 ] , [ 11 , 7 , 1 , 1 , 6, 0 ] , [ 6 , 5 , 9 , 6 , 3 , 3 ] , [ 4 , 3 , 0 , 11 , 4 , 11 ] , [ 0 , 0 , 0 , 2 , 1 , 14 ] ]
- // Question 3
- [ [ 2 , 6 , 0 , 10 , 5 , 0 ] , [ 12 , 6 , 12 , -7 , 9 , -6 ] , [ 12 , 9 , 12 , -3 , 10 , -5 ] , [ 12 , 12 , 12 , -4 , 10 , -6 ] ] ,
- // Question 4
- [ [ 9 , 12 , -8 , 12 , 12 , 0 ] , [ 10 , 10 , 10 , 10 , 10 , -10 ] , [ 3 , 15 , 10 , 15 , 10 , 0 ] , [ 15 , 3 , 19 , 1 , 1 , 0 ] ] ,
- // Question 5
- [ [ 5 , 5 , 5 , 5 , 5 , 5 ] , [ 9 , 6 , 12 , 2 , 2 , -5 ] , [ 10 , 7 , 12 , 2 , 0 , -5 ] , [ 0 , 0 , 0 , 0 , 0 , 0 ] ] ,
- // Question 6
- [ [ 0 , 7 , 0 , 15 , 5 , 10 ] , [ 12 , 10 , 15 , 2 , 12 , -8 ] , [ 0 , 0 , 0 , 15 , 5 , 15 ] , [ 12 , 10 , 15 , 2 , 12 , -8 ] ] ,
- // Question 7
- [ [ 0 , 0 , 0 , 12 , 12 , 0 ] , [ 12 , 10 , 15 , 0 , 0 , 0 ] , [ 6 , 0 , 0 , 15 , 10 , 0 ] , [ 5 , 5 , 5 , 5 , 5 , 5 ] ] ,
- // Question 8
- [ [ 10 , 13 , 15 , 2 , 12 , 0 ] , [ 12 , 10 , 15 , 2 , 12 , 2 ] , [ 13 , 2 , 15 , 15 , 10 , 0 ] , [ 15 , 13 , 10 , -8 , 1 , -9 ] ] ,
- // Question 9
- [ [ 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 15 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 0 ] ] ,
- // Question 10
- [ [ 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 15 , 13 , 0 , 0 ] , [ 10 , 0 , 10 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 10 , 0 ] ] ,
- ]
- /*
- If you want to see all of the possible results at the same time,
- (to help you edit your page) modify the following to be:
- var always_show = true
- To make the page work properly, it should be:
- var always_show = false
- */
- var always_show = false
- // ]]>
- </script>
- <h1>
- Picking where to eat for dinner can be the hardest decision of the day...let us help you!
- </h1>>
- <div id = "main_question"> What should you eat for dinner? </div>
- <div class = "questions">
- <ol>
- <!------------------
- QUESTIONS GO BELOW
- ------------------!>
- <!--Question 1--!>
- <li> What is your favorite type of Food?
- <label class="choice"> <input type="radio" name="q1" value="a1"/> Mexican </label>
- <label class="choice"> <input type="radio" name="q1" value="a2"/> Chinese </label>
- <label class="choice"> <input type="radio" name="q1" value="a3"/> Italian </label>
- <label class="choice"> <input type="radio" name="q1" value="a4"/> Indian </label>
- <!--Question 2--!>
- <li> How hungry are you?
- <label class="choice"> <input type="radio" name="q2" value="a1"/> I am starving </label>
- <label class="choice"> <input type="radio" name="q2" value="a2"/> I has been about 5 hours since my last meal </label>
- <label class="choice"> <input type="radio" name="q2" value="a3"/> I am always hungry! </label>
- <label class="choice"> <input type="radio" name="q2" value="a4"/> I just ate </label>
- <label class="choice"> <input type="radio" name="q2" value="a5"/> I am pretty full </label>
- <!--Question 3--!>
- <li> How many people are you eating with?
- <label class="choice"> <input type="radio" name="q3" value="a1"/> 0 </label>
- <label class="choice"> <input type="radio" name="q3" value="a2"/> 1 </label>
- <label class="choice"> <input type="radio" name="q3" value="a3"/> 4 </label>
- <label class="choice"> <input type="radio" name="q3" value="a4"/> 5 </label>
- <!--Question 4--!>
- <li> How far are you willing to travel to eat?
- <label class="choice"> <input type="radio" name="q4" value="a1"/> Not too far </label>
- <label class="choice"> <input type="radio" name="q4" value="a2"/> I dont care as long as I get food </label>
- <label class="choice"> <input type="radio" name="q4" value="a3"/> I prefer takeout </label>
- <label class="choice"> <input type="radio" name="q4" value="a4"/> I will travel hours for good food </label>
- <!--Question 5--!>
- <li> How was your day?
- <label class="choice"> <input type="radio" name="q5" value="a1"/> Great! </label>
- <label class="choice"> <input type="radio" name="q5" value="a2"/> Could have been better </label>
- <label class="choice"> <input type="radio" name="q5" value="a3"/> Super busy </label>
- <label class="choice"> <input type="radio" name="q5" value="a4"/> Why does this matter? </label>
- <!--Question 6--!>
- <li> How much time do you have to eat
- <label class="choice"> <input type="radio" name="q6" value="a1"/> 30 minutes max </label>
- <label class="choice"> <input type="radio" name="q6" value="a2"/> trying to socialize through dinner </label>
- <label class="choice"> <input type="radio" name="q6" value="a3"/> No time, I have to multi-task and finish up all my work </label>
- <label class="choice"> <input type="radio" name="q6" value="a4"/> I have no plans for tonight...no rush </label>
- <!--Question 7--!>
- <li> How do you like your food?
- <label class="choice"> <input type="radio" name="q7" value="a1"/> Mild </label>
- <label class="choice"> <input type="radio" name="q7" value="a2"/> Spicy </label>
- <label class="choice"> <input type="radio" name="q7" value="a3"/> Sweet </label>
- <label class="choice"> <input type="radio" name="q7" value="a4"/> Moderate mix of everything </label>
- <!--Question 8--!>
- <li> Who are you eating with?
- <label class="choice"> <input type="radio" name="q8" value="a1"/> My family </label>
- <label class="choice"> <input type="radio" name="q8" value="a2"/> My friends </label>
- <label class="choice"> <input type="radio" name="q8" value="a3"/> Myself </label>
- <label class="choice"> <input type="radio" name="q8" value="a4"/> It is a date </label>
- <!--Question 9--!>
- <li> What is your favorite fruit?
- <label class="choice"> <input type="radio" name="q9" value="a1"/> I do not eat fruit </label>
- <label class="choice"> <input type="radio" name="q9" value="a2"/> Mango </label>
- <label class="choice"> <input type="radio" name="q9" value="a3"/> Banana </label>
- <label class="choice"> <input type="radio" name="q9" value="a4"/> Orange </label>
- <!--Question 10--!>
- <li> Favorite Vegetable?
- <label class="choice"> <input type="radio" name="q10" value="a1"/> I do not eat vegetables </label>
- <label class="choice"> <input type="radio" name="q10 value="a2"/> I love all vegetables </label>
- <label class="choice"> <input type="radio" name="q10" value="a3"/> Peppers </label>
- <label class="choice"> <input type="radio" name="q10" value="a4"/> Tomatoes </label>
- </ol>
- <p>
- <!--Submit Button--!>
- <button type="button" onclick="select()"> What should I eat for dinner? </button>
- <div id="incomplete">
- <p>
- You have not answered all of the questions yet.
- <!---------------
- RESULTS GO BELOW
- ------------------!>
- <!--Result 1--!>
- <div id="r1">
- <p>
- You should try Mexican Amigos!
- Here you will experience an authentic variety of Mexican cuisine! A family favorite!
- <p>
- <img src="https://www.topuniversities.com/sites/default/files/styles/lead_article_image/public/blogs/lead-images/mexican-food-2.jpg" width="200"/>
- </div>
- <!--Result 2--!>
- <div id="r2">
- <p>
- You should try Chinois!
- Here you will experience chinese Cuisine infused with Indian. Great for dinner and they have great take out options, treat yourself!
- <p>
- <img src="https://i.ndtvimg.com/i/2016-06/chinese-625_625x350_81466064119.jpg?downsize=630:380&output-quality=70&output-format=webp" width="200"/>
- </div>
- <!--Result 3--!>
- <div id="r3">
- <p>
- You should try the Host!
- Here you will experience the best Indian food in all of North America! With various locations and a diverse menu, there is something for everyone!
- <p>
- <img src="https://images.musement.com/cover/0002/25/thumb_124685_cover_header.jpeg" width="200"/>
- </div>
- <p>
- <!--Result 4--!>
- <div id="r4">
- <p>
- You should try Subway!
- A healthier option to fast food, subway restaurants are fast and customizable!
- <p>
- < img src="http://monreadshoppingcentre.ie/wp-content/uploads/2014/03/monread-subway.jpg" width="200"/>
- </div>
- <!--Result 5--!>
- <div id="r5">
- <p>
- You should try East Side Marios!
- This is a family favorite! Enjoy your meal in a italian atmosphere and home of all you can eat pasta.
- <p>
- <img src="https://www.perkopolis.com/images/East-Side-Marios_2.jpg?resizeid=4&resizeh=600&resizew=600" width="200"/>
- </div>
- <!--Result 6--!>
- <div id="r6">
- <p>
- Maybe thats is enough food for today!
- Too much food may sometimes be a bad thing...get some rest there is a lot more to eat tomorrow
- <p>
- img src="https://cdn5.f-cdn.com/contestentries/96249/11353944/53f1f7e6ebeee_thumb900.jpg" width="200"
- </div>
- <script>
- // <![CDATA[
- /**********************************************
- Do not edit the following code unless you are comfortable with JavaScript.
- **********************************************/
- var verbose = true
- var num_selections = 0
- while (1) {
- var e = document.getElementById('r' + (num_selections + 1))
- if (e === null) break
- ++num_selections
- }
- if (num_selections == 0) window.alert('unexpected: no section ids (r1, r2, etc.)')
- if (verbose) console.log('num_selections = ' + num_selections)
- num_questions = 0
- while (1) {
- var e = document.getElementsByName('q' + (num_questions + 1))
- if (e.length == 0) break
- ++num_questions
- if (e.length < 2) window.alert('unexpected: q' + num_questions + ' has less than 2 answers')
- }
- if (num_questions == 0) window.alert('unexpected: no question names (q1, q2, etc.)')
- if (verbose) console.log('num_questions = ' + num_questions)
- function hide_selections() {
- if (!always_show) {
- if (verbose) console.log('hide_selections()')
- document.getElementById('incomplete').style.display = 'none'
- for (var s=1; s <= num_selections; ++s) {
- document.getElementById('r' + s).style.display = 'none'
- }
- }
- }
- hide_selections()
- function select() {
- if (verbose) console.log('select()')
- hide_selections()
- var incomplete = false
- var scores = new Array(num_selections)
- for (var s = 1; s <= num_selections; ++s) scores[s-1] = 0
- for (var q = 1; q <= num_questions; ++q) {
- var answers = document.getElementsByName('q' + q)
- var choice = false
- for (var a = 0; a < answers.length; ++a) {
- if (answers[a].checked) {
- choice = answers[a].value
- break
- }
- }
- if (choice === false) {
- incomplete = true
- break
- }
- if (verbose) console.log('q' + q + ': answer = ' + choice)
- var answer = choice.substr(1)
- for (var s = 1; s <= num_selections; ++s) {
- var w = weights[q-1][answer-1][s-1]
- if (typeof w === 'undefined') window.alert('error: could not find weight for q' + q + 'a' + answer + 'r' + s)
- scores[s-1] += w
- if (verbose) console.log('score[' + s + '] += ' + w)
- }
- }
- if (incomplete) {
- if (verbose) console.log('incomplete')
- document.getElementById('incomplete').style.display = 'block'
- } else {
- var maxscore = Number.MIN_VALUE
- var pick = 0
- for (var s = 1; s <= num_selections; ++s) {
- if (verbose) console.log('score[' + s + '] == ' + scores[s-1])
- if (scores[s-1] > maxscore) {
- pick = s
- maxscore = scores[s-1]
- }
- }
- if (verbose) console.log('pick = r' + pick)
- document.getElementById('r' + pick).style.display = 'block'
- }
- }
- // ]]>
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement