Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Quiz</title>
- <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
- <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
- <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
- </head>
- <body>
- <div id="parent">
- </div>
- <button id="results" class="btn">kirim jawaban</button>
- <script>
- $(function(){
- $(document).ready(function()
- {
- $("#results").click(function() {
- var result = false;
- var i;
- var score=0;
- var tnya = $('[name=pertanyaan]').length;
- for(i=0;i<tnya;i++){
- $("[name = question-" + i + "]").each(function(){
- if ($(this).is(':checked') == true){
- if($("[name=question-3]").val() === "A"){
- score = score +10;
- }
- else if($("[name=question-4]").val() === "B"){
- score = score +10;
- }
- else if($("[name=question-5]").val() === "C"){
- score = score +10;
- }
- else if($("[name=question-6]").val() === "A"){
- score = score +10;
- }
- else if($("[name=question-7]").val() === "B"){
- score = score +10;
- }
- result = true;
- return false;
- }
- else {
- result = false;
- }
- console.log($(this).is(':checked'));
- });
- }
- if (!result) {
- alert( " harus di isi semua pertanyaan");
- }
- else {
- alert('congratulation, your score : '+score);
- }
- });
- });
- $.getJSON('http://localhost:85/fuel/api/campaign/13', function(data) {
- var dataJson = JSON.stringify(data);
- //console.log(data.msg[0].rows.name);
- //$("#campaignName").html(data.msg[0].campaign.name);
- //$("#questionName").html(data.msg[0].rows.name);
- var temp='';
- $.each(data.msg[0].rows, function(e,dt){
- temp += '<form action = "index.php" method = "post">';
- temp += '<div class="jumbotron" >';
- temp += '<center><label name="pertanyaan">' + dt.name + '</label></center>';
- temp += '<center><img src="' + dt.image + '" width="100px" height="100px"></center><br>';
- console.log(dt.a);
- if ( dt.a.length >= 1) {
- temp += '<div class="row">';
- $.each(dt.a, function(e,at){
- console.log(at);
- temp += '<div class="col-md-4">';
- temp += '<div class="caption">';
- temp += '<input type="radio" data-flags="radio" name="question-' + dt.id + '" value="' + at.alias + '"> ' + at.alias + ' ' + at.name + '<br>';
- temp += '</div></div>';
- });
- temp += '</div>';
- }
- temp += '</div>';
- //console.log(dt.img);
- });
- temp += '</form>';
- //$('#getJSON-results').html(dataJson);
- $('#parent').html(temp);
- //$('#child').html(temp);
- });
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement