0

I`m having an assignment where I have to make a simple quiz, each right question must add 1 points to the score, here is my code

let app = new Vue({
  el: '#app',
  data: {
    crameworks: [
    {skor: 0}
    ],
    frameworks: [
      { name: 'A.Charles Bababage', 
      votes : true },
      { name: 'B.Naruto',
       votes : false },
      { name: 'C.Sasuke',
       votes : false },
      { name: 'D.Belva',
       votes : false},
       ],
    grameworks : [
{ jawaban: 'A.Pochinok', 
      votes : true },
      { jawaban: 'B.Miramar',
       votes : false },
      { jawaban: 'C.Tambang',
       votes : false },
      { jawaban: 'D.Kampong',
       votes : false}
    ],
    vrameworks : [
      { answer: 'A.Bisa',
      votes : false},
      { answer: 'B.Tidak',
      votes : true},
      { answer: 'C.Mungkin',
      votes : false},
      { answer: 'D.isin ku aa crown',
      votes : false}
    ]
  },
  methods:{
  skor(){
    if(this.votes == true){
      this.crameworks[0].skor + 1
    }
  }
  }

})

here is my html file

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>My App</title>
    <script src="https://cdn.jsdelivr.net/npm/vue">
    </script>
</head>

<body>
    <div id="app">
        <ul>
        1.Pembuat Printer adalah
        <br>
        <p v-for="f in frameworks">
          <input type="radio">
                {{f.name}}
                        </p>
      </ul>
      <ul>
        2.Berikut area dalam game PUBG, Kecuali 
        <br>
            <p v-for="g in grameworks">
              <input type="radio">
            {{g.jawaban}} 
          </p>
      </ul>
      <ul>
        3.Bisakah Senjata Kar98K menggunakan Extended Sniper?
          <p v-for="v in vrameworks">
              <input type="radio">
              {{v.answer}}
          </p>
    <button type="submit" v-on:Click="skor">Jawab</button>
    <h1>Skor :  {{skor}}</h1>
    <script src="index.js"></script>
    </div>
  </body>
</html>

I give a true statement in every right answer so if user choose an answer with true statement it should be adding 1 points to the score and print the score, the problem is I get this warning (function () { [native code] }) when I'm trying to print the score, the score should be 0 at first

2
  • 1
    You've got a property called skor that's a function, and inside that function you try to add 1 to it. That does not make sense; you need a different property to keep the score value. Commented Jan 29, 2019 at 15:09
  • im sorry this is my first assignment on vue, why it doesn't make sense? and what is different property that i needed ? Commented Jan 29, 2019 at 15:11

3 Answers 3

2

The error is in skor, you forgot to add these parenthesis after it (), that's how you call a javascript function

<h1>Skor :  {{skor()}}</h1>
Sign up to request clarification or add additional context in comments.

Comments

1

You're using the function skor to determine when to add +1, but your variable you're assigning to is wrong. It should be this.crameworks[0].skor + 1. Also, that should be the number 0 and not the string '0' in your data initialization.

You have also declared data twice in your Vue initializer. Combine those into a single data: {} object.

2 Comments

i still got the '(function () { [native code] })' error from your answer
i still got the error after combine the data method
0

this.skor refers to the method, so the following is referencing the method:

<h1>Skor :  {{skor}}</h1>

In order to access the data you need to reference it in the right spot, crameworks[0].skor:

<h1>Skor :  {{crameworks[0].skor}}</h1>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.