Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3.     <title>Quiz</title>
  4.     <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
  5.     <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
  6.     <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
  7. </head>
  8. <body>
  9.  
  10. <div id="parent">
  11.    
  12. </div>
  13. <button id="results" class="btn">kirim jawaban</button>
  14.  
  15.  
  16. <script>
  17. $(function(){
  18.     $(document).ready(function()
  19.     {
  20.             $("#results").click(function() {
  21.                 var result = false;
  22.                 var i;
  23.                 var score=0;
  24.                 var tnya = $('[name=pertanyaan]').length;
  25.                
  26.                 for(i=0;i<tnya;i++){
  27.                     $("[name = question-" + i + "]").each(function(){
  28.                         if ($(this).is(':checked') == true){
  29.                             if($("[name=question-3]").val() === "A"){
  30.                                 score = score +10;
  31.                             }
  32.                             else if($("[name=question-4]").val() === "B"){
  33.                                 score = score +10;
  34.                             }
  35.                             else if($("[name=question-5]").val() === "C"){
  36.                                 score = score +10;
  37.                             }
  38.                             else if($("[name=question-6]").val() === "A"){
  39.                                 score = score +10;
  40.                             }
  41.                             else if($("[name=question-7]").val() === "B"){
  42.                                 score = score +10;
  43.                             }
  44.                            
  45.                             result = true;
  46.                             return false;
  47.                         }
  48.                         else  {
  49.                             result = false;
  50.                         }
  51.                         console.log($(this).is(':checked'));
  52.                     });
  53.                 }
  54.                
  55.                
  56.                 if (!result) {
  57.                     alert( " harus di isi semua pertanyaan");
  58.                 }
  59.                 else {
  60.                    
  61.                     alert('congratulation, your score : '+score);
  62.                 }
  63.                
  64.             });
  65.            
  66.     });
  67.      
  68.    
  69. $.getJSON('http://localhost:85/fuel/api/campaign/13', function(data) {
  70.     var dataJson = JSON.stringify(data);
  71.     //console.log(data.msg[0].rows.name);
  72.     //$("#campaignName").html(data.msg[0].campaign.name);
  73.     //$("#questionName").html(data.msg[0].rows.name);
  74.     var temp='';
  75.     $.each(data.msg[0].rows, function(e,dt){
  76.         temp += '<form action = "index.php" method = "post">';
  77.         temp += '<div class="jumbotron" >';
  78.         temp += '<center><label name="pertanyaan">' + dt.name + '</label></center>';
  79.         temp += '<center><img src="' + dt.image + '" width="100px" height="100px"></center><br>';
  80.        
  81.         console.log(dt.a);
  82.         if ( dt.a.length >= 1) {
  83.             temp += '<div class="row">';
  84.             $.each(dt.a, function(e,at){
  85.                 console.log(at);
  86.                 temp += '<div class="col-md-4">';
  87.                 temp += '<div class="caption">';
  88.                 temp += '<input type="radio" data-flags="radio" name="question-' + dt.id + '" value="' + at.alias + '"> ' + at.alias + ' ' + at.name + '<br>';
  89.                
  90.                 temp += '</div></div>';
  91.                
  92.             });
  93.            
  94.             temp += '</div>';
  95.            
  96.         }
  97.         temp += '</div>';
  98.         //console.log(dt.img);
  99.        
  100.     });
  101.    
  102.     temp += '</form>';
  103.     //$('#getJSON-results').html(dataJson);
  104.    
  105.     $('#parent').html(temp);
  106.    
  107.     //$('#child').html(temp);
  108.    
  109. });
  110.    
  111.    
  112. });
  113.  
  114.        
  115. </script>
  116.  
  117. </body>
  118. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement