Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.94 KB | None | 0 0
  1. <!DOCTYPE html>
  2.  
  3. <html>
  4.  
  5. <head>
  6.  
  7. <title>
  8. What to eat for dinner?
  9. </title>
  10.  
  11. <link rel="stylesheet" type="text/css" href="a9pc_styles.css">
  12. <style>
  13. /* this style just aligns answers vertically */
  14. .choice { display: block; }
  15. </style>
  16.  
  17. </head>
  18.  
  19. <body>
  20.  
  21. <script>
  22. // <![CDATA[
  23. /************************************************************************************
  24.  
  25. This is how you enter the weights for each possible question / answer / result:
  26.  
  27. q: question #
  28. a: answer #
  29. r: result #
  30.  
  31. for example, q1a2r3 determines how r3's score is affected if a2 is picked for q1
  32.  
  33. var weights = [
  34. [[q1a1r1, q1a1r2, q1a1r3, ... q1a1r?], [q1a2r1, q1a2r2, ...], [q1a?s1, ...]],
  35. [[q2a1r1, q2a1r2, ...], [q2a2r1, ...], [q2a?r1, ...]],
  36. ...
  37. [[q?a1r1, q?a1r2, ...], [q?a2r1, ...], [q?a?r1, ...]]
  38. ]
  39.  
  40. *************************************************************************************/
  41.  
  42. /****************
  43. WEIGHTS GO BELOW
  44. *****************/
  45.  
  46. var weights = [
  47.  
  48. // Question 1
  49.  
  50. [ [ 10 , 3 , 5 , 2 , 2 , 0 ] , [ 2 , 10 , 5 , 2 , 2 , 2 ] , [ 3 , 2 , 5 , 5 , 10 , 1 ] , [ 5 , 3 , 10 , 1 , 1 , 2 ] ] ,
  51.  
  52. // Question 2
  53.  
  54. [ [ 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 ] ]
  55.  
  56. // Question 3
  57.  
  58. [ [ 2 , 6 , 0 , 10 , 5 , 0 ] , [ 12 , 6 , 12 , -7 , 9 , -6 ] , [ 12 , 9 , 12 , -3 , 10 , -5 ] , [ 12 , 12 , 12 , -4 , 10 , -6 ] ] ,
  59.  
  60. // Question 4
  61.  
  62. [ [ 9 , 12 , -8 , 12 , 12 , 0 ] , [ 10 , 10 , 10 , 10 , 10 , -10 ] , [ 3 , 15 , 10 , 15 , 10 , 0 ] , [ 15 , 3 , 19 , 1 , 1 , 0 ] ] ,
  63.  
  64. // Question 5
  65.  
  66. [ [ 5 , 5 , 5 , 5 , 5 , 5 ] , [ 9 , 6 , 12 , 2 , 2 , -5 ] , [ 10 , 7 , 12 , 2 , 0 , -5 ] , [ 0 , 0 , 0 , 0 , 0 , 0 ] ] ,
  67.  
  68. // Question 6
  69.  
  70. [ [ 0 , 7 , 0 , 15 , 5 , 10 ] , [ 12 , 10 , 15 , 2 , 12 , -8 ] , [ 0 , 0 , 0 , 15 , 5 , 15 ] , [ 12 , 10 , 15 , 2 , 12 , -8 ] ] ,
  71.  
  72. // Question 7
  73.  
  74. [ [ 0 , 0 , 0 , 12 , 12 , 0 ] , [ 12 , 10 , 15 , 0 , 0 , 0 ] , [ 6 , 0 , 0 , 15 , 10 , 0 ] , [ 5 , 5 , 5 , 5 , 5 , 5 ] ] ,
  75.  
  76. // Question 8
  77.  
  78. [ [ 10 , 13 , 15 , 2 , 12 , 0 ] , [ 12 , 10 , 15 , 2 , 12 , 2 ] , [ 13 , 2 , 15 , 15 , 10 , 0 ] , [ 15 , 13 , 10 , -8 , 1 , -9 ] ] ,
  79.  
  80. // Question 9
  81.  
  82. [ [ 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 15 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 0 ] ] ,
  83.  
  84. // Question 10
  85.  
  86. [ [ 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 15 , 13 , 0 , 0 ] , [ 10 , 0 , 10 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 10 , 0 ] ] ,
  87.  
  88.  
  89. ]
  90.  
  91. /*
  92. If you want to see all of the possible results at the same time,
  93. (to help you edit your page) modify the following to be:
  94. var always_show = true
  95.  
  96. To make the page work properly, it should be:
  97. var always_show = false
  98. */
  99.  
  100. var always_show = false
  101.  
  102. // ]]>
  103. </script>
  104.  
  105. <h1>
  106. Picking where to eat for dinner can be the hardest decision of the day...let us help you!
  107.  
  108.  
  109. </h1>>
  110. <div id = "main_question"> What should you eat for dinner? </div>
  111.  
  112. <div class = "questions">
  113. <ol>
  114. <!------------------
  115. QUESTIONS GO BELOW
  116. ------------------!>
  117.  
  118. <!--Question 1--!>
  119.  
  120. <li> What is your favorite type of Food?
  121. <label class="choice"> <input type="radio" name="q1" value="a1"/> Mexican </label>
  122. <label class="choice"> <input type="radio" name="q1" value="a2"/> Chinese </label>
  123. <label class="choice"> <input type="radio" name="q1" value="a3"/> Italian </label>
  124. <label class="choice"> <input type="radio" name="q1" value="a4"/> Indian </label>
  125.  
  126. <!--Question 2--!>
  127.  
  128. <li> How hungry are you?
  129. <label class="choice"> <input type="radio" name="q2" value="a1"/> I am starving </label>
  130. <label class="choice"> <input type="radio" name="q2" value="a2"/> I has been about 5 hours since my last meal </label>
  131. <label class="choice"> <input type="radio" name="q2" value="a3"/> I am always hungry! </label>
  132. <label class="choice"> <input type="radio" name="q2" value="a4"/> I just ate </label>
  133. <label class="choice"> <input type="radio" name="q2" value="a5"/> I am pretty full </label>
  134.  
  135. <!--Question 3--!>
  136.  
  137. <li> How many people are you eating with?
  138. <label class="choice"> <input type="radio" name="q3" value="a1"/> 0 </label>
  139. <label class="choice"> <input type="radio" name="q3" value="a2"/> 1 </label>
  140. <label class="choice"> <input type="radio" name="q3" value="a3"/> 4 </label>
  141. <label class="choice"> <input type="radio" name="q3" value="a4"/> 5 </label>
  142.  
  143. <!--Question 4--!>
  144.  
  145. <li> How far are you willing to travel to eat?
  146. <label class="choice"> <input type="radio" name="q4" value="a1"/> Not too far </label>
  147. <label class="choice"> <input type="radio" name="q4" value="a2"/> I dont care as long as I get food </label>
  148. <label class="choice"> <input type="radio" name="q4" value="a3"/> I prefer takeout </label>
  149. <label class="choice"> <input type="radio" name="q4" value="a4"/> I will travel hours for good food </label>
  150.  
  151. <!--Question 5--!>
  152.  
  153. <li> How was your day?
  154. <label class="choice"> <input type="radio" name="q5" value="a1"/> Great! </label>
  155. <label class="choice"> <input type="radio" name="q5" value="a2"/> Could have been better </label>
  156. <label class="choice"> <input type="radio" name="q5" value="a3"/> Super busy </label>
  157. <label class="choice"> <input type="radio" name="q5" value="a4"/> Why does this matter? </label>
  158.  
  159. <!--Question 6--!>
  160.  
  161. <li> How much time do you have to eat
  162. <label class="choice"> <input type="radio" name="q6" value="a1"/> 30 minutes max </label>
  163. <label class="choice"> <input type="radio" name="q6" value="a2"/> trying to socialize through dinner </label>
  164. <label class="choice"> <input type="radio" name="q6" value="a3"/> No time, I have to multi-task and finish up all my work </label>
  165. <label class="choice"> <input type="radio" name="q6" value="a4"/> I have no plans for tonight...no rush </label>
  166.  
  167. <!--Question 7--!>
  168.  
  169. <li> How do you like your food?
  170. <label class="choice"> <input type="radio" name="q7" value="a1"/> Mild </label>
  171. <label class="choice"> <input type="radio" name="q7" value="a2"/> Spicy </label>
  172. <label class="choice"> <input type="radio" name="q7" value="a3"/> Sweet </label>
  173. <label class="choice"> <input type="radio" name="q7" value="a4"/> Moderate mix of everything </label>
  174.  
  175. <!--Question 8--!>
  176.  
  177. <li> Who are you eating with?
  178. <label class="choice"> <input type="radio" name="q8" value="a1"/> My family </label>
  179. <label class="choice"> <input type="radio" name="q8" value="a2"/> My friends </label>
  180. <label class="choice"> <input type="radio" name="q8" value="a3"/> Myself </label>
  181. <label class="choice"> <input type="radio" name="q8" value="a4"/> It is a date </label>
  182.  
  183. <!--Question 9--!>
  184.  
  185. <li> What is your favorite fruit?
  186. <label class="choice"> <input type="radio" name="q9" value="a1"/> I do not eat fruit </label>
  187. <label class="choice"> <input type="radio" name="q9" value="a2"/> Mango </label>
  188. <label class="choice"> <input type="radio" name="q9" value="a3"/> Banana </label>
  189. <label class="choice"> <input type="radio" name="q9" value="a4"/> Orange </label>
  190.  
  191. <!--Question 10--!>
  192.  
  193. <li> Favorite Vegetable?
  194. <label class="choice"> <input type="radio" name="q10" value="a1"/> I do not eat vegetables </label>
  195. <label class="choice"> <input type="radio" name="q10 value="a2"/> I love all vegetables </label>
  196. <label class="choice"> <input type="radio" name="q10" value="a3"/> Peppers </label>
  197. <label class="choice"> <input type="radio" name="q10" value="a4"/> Tomatoes </label>
  198. </ol>
  199.  
  200. <p>
  201. <!--Submit Button--!>
  202.  
  203. <button type="button" onclick="select()"> What should I eat for dinner? </button>
  204.  
  205. <div id="incomplete">
  206.  
  207. <p>
  208. You have not answered all of the questions yet.
  209.  
  210.  
  211. <!---------------
  212. RESULTS GO BELOW
  213. ------------------!>
  214.  
  215. <!--Result 1--!>
  216.  
  217. <div id="r1">
  218.  
  219. <p>
  220. You should try Mexican Amigos!
  221. Here you will experience an authentic variety of Mexican cuisine! A family favorite!
  222.  
  223. <p>
  224. <img src="https://www.topuniversities.com/sites/default/files/styles/lead_article_image/public/blogs/lead-images/mexican-food-2.jpg" width="200"/>
  225.  
  226.  
  227. </div>
  228.  
  229. <!--Result 2--!>
  230.  
  231. <div id="r2">
  232.  
  233. <p>
  234. You should try Chinois!
  235. Here you will experience chinese Cuisine infused with Indian. Great for dinner and they have great take out options, treat yourself!
  236. <p>
  237. <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"/>
  238. </div>
  239.  
  240. <!--Result 3--!>
  241.  
  242. <div id="r3">
  243.  
  244. <p>
  245. You should try the Host!
  246. 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!
  247. <p>
  248. <img src="https://images.musement.com/cover/0002/25/thumb_124685_cover_header.jpeg" width="200"/>
  249. </div>
  250.  
  251. <p>
  252.  
  253. <!--Result 4--!>
  254.  
  255. <div id="r4">
  256.  
  257. <p>
  258. You should try Subway!
  259. A healthier option to fast food, subway restaurants are fast and customizable!
  260. <p>
  261. < img src="http://monreadshoppingcentre.ie/wp-content/uploads/2014/03/monread-subway.jpg" width="200"/>
  262.  
  263. </div>
  264.  
  265. <!--Result 5--!>
  266.  
  267. <div id="r5">
  268.  
  269. <p>
  270. You should try East Side Marios!
  271. This is a family favorite! Enjoy your meal in a italian atmosphere and home of all you can eat pasta.
  272.  
  273. <p>
  274. <img src="https://www.perkopolis.com/images/East-Side-Marios_2.jpg?resizeid=4&resizeh=600&resizew=600" width="200"/>
  275. </div>
  276.  
  277. <!--Result 6--!>
  278.  
  279. <div id="r6">
  280.  
  281. <p>
  282. Maybe thats is enough food for today!
  283. Too much food may sometimes be a bad thing...get some rest there is a lot more to eat tomorrow
  284.  
  285. <p>
  286. img src="https://cdn5.f-cdn.com/contestentries/96249/11353944/53f1f7e6ebeee_thumb900.jpg" width="200"
  287. </div>
  288.  
  289.  
  290. <script>
  291. // <![CDATA[
  292. /**********************************************
  293. Do not edit the following code unless you are comfortable with JavaScript.
  294. **********************************************/
  295.  
  296. var verbose = true
  297.  
  298. var num_selections = 0
  299. while (1) {
  300. var e = document.getElementById('r' + (num_selections + 1))
  301. if (e === null) break
  302. ++num_selections
  303. }
  304. if (num_selections == 0) window.alert('unexpected: no section ids (r1, r2, etc.)')
  305. if (verbose) console.log('num_selections = ' + num_selections)
  306.  
  307. num_questions = 0
  308. while (1) {
  309. var e = document.getElementsByName('q' + (num_questions + 1))
  310. if (e.length == 0) break
  311. ++num_questions
  312. if (e.length < 2) window.alert('unexpected: q' + num_questions + ' has less than 2 answers')
  313. }
  314. if (num_questions == 0) window.alert('unexpected: no question names (q1, q2, etc.)')
  315. if (verbose) console.log('num_questions = ' + num_questions)
  316.  
  317. function hide_selections() {
  318. if (!always_show) {
  319. if (verbose) console.log('hide_selections()')
  320. document.getElementById('incomplete').style.display = 'none'
  321. for (var s=1; s <= num_selections; ++s) {
  322. document.getElementById('r' + s).style.display = 'none'
  323. }
  324. }
  325. }
  326.  
  327. hide_selections()
  328.  
  329. function select() {
  330. if (verbose) console.log('select()')
  331. hide_selections()
  332. var incomplete = false
  333. var scores = new Array(num_selections)
  334. for (var s = 1; s <= num_selections; ++s) scores[s-1] = 0
  335. for (var q = 1; q <= num_questions; ++q) {
  336. var answers = document.getElementsByName('q' + q)
  337. var choice = false
  338. for (var a = 0; a < answers.length; ++a) {
  339. if (answers[a].checked) {
  340. choice = answers[a].value
  341. break
  342. }
  343. }
  344. if (choice === false) {
  345. incomplete = true
  346. break
  347. }
  348. if (verbose) console.log('q' + q + ': answer = ' + choice)
  349. var answer = choice.substr(1)
  350. for (var s = 1; s <= num_selections; ++s) {
  351. var w = weights[q-1][answer-1][s-1]
  352. if (typeof w === 'undefined') window.alert('error: could not find weight for q' + q + 'a' + answer + 'r' + s)
  353. scores[s-1] += w
  354. if (verbose) console.log('score[' + s + '] += ' + w)
  355. }
  356. }
  357. if (incomplete) {
  358. if (verbose) console.log('incomplete')
  359. document.getElementById('incomplete').style.display = 'block'
  360. } else {
  361. var maxscore = Number.MIN_VALUE
  362. var pick = 0
  363. for (var s = 1; s <= num_selections; ++s) {
  364. if (verbose) console.log('score[' + s + '] == ' + scores[s-1])
  365. if (scores[s-1] > maxscore) {
  366. pick = s
  367. maxscore = scores[s-1]
  368. }
  369. }
  370. if (verbose) console.log('pick = r' + pick)
  371. document.getElementById('r' + pick).style.display = 'block'
  372. }
  373. }
  374. // ]]>
  375. </script>
  376.  
  377. </body>
  378.  
  379. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement