The function() method in Vue.js is executed natively

I have a project where I need to create a simple quiz. Each correct answer should earn 1 point towards the score. Below is the code I am using:

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
    }
  }
  }

})

Below 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. The creator of the printer is
        <br>
        <p v-for="f in frameworks">
          <input type="radio">
                {{f.name}}
                        </p>
      </ul>
      <ul>
        2. Which area does not exist in PUBG game?
        <br>
            <p v-for="g in grameworks">
              <input type="radio">
            {{g.jawaban}} 
          </p>
      </ul>
      <ul>
        3. Can the Kar98K weapon use Extended Sniper scope?
          <p v-for="v in vrameworks">
              <input type="radio">
              {{v.answer}}
          </p>
    <button type="submit" v-on:Click="skor">Answer</button>
    <h1>Score :  {{score}}</h1>
    <script src="index.js"></script>
    </div>
  </body>
</html>

For each correct answer, I have set a true statement. However, when trying to print the score, I get a warning message "(function () { [native code] })". The initial score should be set to 0.

Answer №1

The mistake lies in the skor variable, you neglected to include parentheses after it (), which is the proper way to invoke a javascript function

<h1>Score :  {{skor()}}</h1>

Answer №2

The function skor is being used to decide when to increment by +1, but there seems to be an error in the variable you are assigning to. It should actually be this.crameworks[0].skor + 1. Additionally, make sure that the value is the number 0 and not the string '0' when initializing your data.

You have redundantly declared the variable data twice in your Vue initializer. Consolidate them into a single data: {} object.

Answer №3

The term this.skor is specifically referring to a method in this context, so any mention of it is related to that method:

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

To retrieve the data correctly, make sure to pinpoint the exact location where it can be found, like so: crameworks[0].skor:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The fetch API in Javascript encounters issues when employed within an EJS file

I'm attempting to retrieve a file named files.json from the main directory of my locally hosted NodeJS backend and then display its contents in the console. <script> fetch("./files.json") .then(res => { return res.json() ...

Getting a JWT token from Express to Angular using ngResource: A step-by-step guide

Currently, I am utilizing a jwt token for user registration validation. A unique URL is generated and sent to the user via email, which leads them to the authentication page. On the server side, the token is decoded and I need to transmit this JSON data to ...

When the URL is modified, triggering an event to load

Is there a way to make a page load directly to a specific section and automatically open an accordion? For instance, I have a page with multiple accordions displayed vertically. I already know that using id's in the URL like page#accordion1 will scro ...

The datatable in Vuetify fails to update following an Axios request

I'm working on creating a basic form and datatable using Vuetify's datatable component. The datatable fetches data from an API and also sends data to the API. The datatable is populated after the page loads, and I can also submit data using Axios ...

Selenium's WebDriver getAttribute function can return an object of type "object",

In my selenium script, I aim to extract text from table columns following the cell with the specified value. Although the script functions, I encounter an issue where getText() returns [Object Object] in my node.js console. I have attempted various method ...

How can I style the outermost div of a jQuery UI dialog window using CSS?

I currently utilize jquery-ui for the creation of a dialog window, with the designated div to be displayed having the class 'dialog'. First, let's observe the HTML structure : <div class="click_me"> Click Me </div><!-- end o ...

What is the method to adjust the anchor point for a MUI popover?

I currently have the following code for handling a popover: const [open, setOpen] = useState(false); const anchorRef = createRef() const handleClose = () => { setOpen(false); }; const handleClick = useCallback( (event: MouseEvent<H ...

Choose a country from a modal in a React application

click here for image description I need help implementing the screenshot above. My goal is to change the default country name and flag when a user clicks on the country dropdown menu. I have been using headless UI so far, but I'm struggling to figure ...

AngularJS, sort through "afoo" excluding "foo"

I am attempting to implement a filter within an ng-repeat Main.HTML <table> <tr ng-repeat="param in MyParam | filter: UnrequestValue"> <td>{{param.Label}}</td> </tr> </table> Main.js MyParam: ...

What is the process for printing with JQuery?

I have nested divs with dynamically generated images in my HTML code. My problem is that when I click the print button, I want the corresponding image to be printed. <div id="outputTemp" style="display:none"> <div id="rightoutputimgae"> <di ...

Using HTML or JavaScript to generate a multitude of identical HTML elements on a webpage

I am currently designing a page that requires the presence of numerous tree illustrations with leaves, spanning across the width at the bottom of the page. I have considered two methods to achieve this. One option is to create a single set of trees and lea ...

Creating a unique input box using CSS and HTML

Could someone help me achieve an input box like the one shown in the image below? https://i.stack.imgur.com/XtVNj.png Since I am new to CSS, I am not sure how to put text inside the border of an input box. Should I style the input directly or create a di ...

How to make views in React Native adjust their size dynamically in a scrollview with paging functionality

Has anyone successfully implemented a ScrollView in React Native with paging enabled to swipe through a series of images? I am having trouble making the image views fill each page of the scroll view without hardcoding width and height values for the image ...

Why does my 'click' event listener only work for the first two <li>'s and not the others?

I am new to programming and recently achieved success with my 'click' eventListener. When clicking on the first two li elements within the ul, the class of the div toggles on and off as expected. However, I encountered an issue where clicking on ...

"Troubleshooting a 400 Bad Request Error in Node.js and Express for a

It seems like I must be making a silly mistake, because this should be a simple task. All I want to do is send a POST request in an Express route. This is my app.js: var express = require('express'); var path = require('path'); var f ...

What is preferable: defining JSON schema properties or utilizing oneOf conditions within an array of objects

I am looking to represent a variety of objects in a schema through an array called contents. This array can include any number of elements, but they must fall into one of two categories: one type represents text while the other type represents images. Up ...

Is the Site Header displayed depending on the scroll position and direction of scrolling?

On my website, I have a header that I want to hide when the user scrolls down 100px and show again when they scroll up 50px. I attempted to write a script for this functionality, but it doesn't seem to be working as expected. CSS /* This CSS rule w ...

Updating the content of a list item on the fly using React

After spending all day on this, I am feeling a bit frazzled. Trying to achieve what would take 20 seconds in JQuery has proven to be quite the challenge in React ¯\_(ツ)_/¯ In my application, tags are ranked by importance from 1 to 9. Simple enoug ...

Embed script tags into static HTML files served by a Node.js server

Looking to set up a Node server where users can request multiple pages from a static folder, and have the server inject a custom tag before serving them. Has anyone had success doing this? I've tried with http-proxy without success - not sure if a pro ...

Differences in characteristics of Javascript and Python

As I tackle an exam question involving the calculation of delta for put and call options using the Black and Scholes formula, I stumbled upon a helpful website . Upon inspecting their code, I discovered this specific function: getDelta: function(spot, str ...