Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8582961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:25:28+00:00 2026-06-11T21:25:28+00:00

am trying to develop a quiz snippet with drag and drop and end up

  • 0

am trying to develop a quiz snippet with drag and drop and end up with this code where its always showing result as 1 the result is not incrementing…..

i tried many ways but its not incrementing…..

javascript:

here is my code which i used in the

 <script>
    function allowDropi(ev)
    {
        ev.preventDefault();
    }

    function dragi(ev)
    {
        ev.dataTransfer.setData("Text",ev.target.id);
    }

    function dropi(ev)
    {
        ev.preventDefault();
        var data=ev.dataTransfer.getData("Text");
        ev.target.appendChild(document.getElementById(data));

        result1=0;

        if(ev.dataTransfer.getData("Text")==="drag2i")
        {
            result1++;

        }


        if(ev.dataTransfer.getData("Text")==="dra2i")
        {
            result1++;
        }


        if(ev.dataTransfer.getData("Text")==="dr2i")
        {
            result1++;
        }


        if(ev.dataTransfer.getData("Text")==="2i")
        {
            result1++;
        }


        if(ev.dataTransfer.getData("Text")==="d2i")
        {
            result1++;
        }

         document.getElementById('boldStuff6').innerHTML = result1;
    }

    alert(result1);

    </script>

where am i going wrong please check mycode and help me in getting the result…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:25:29+00:00Added an answer on June 11, 2026 at 9:25 pm

    The reason is that everytime you call this function result is being set to 0 by “result1=0” and then you are incremeting it afterwards.

    If you want to keep count of the result you will neet to make result as a property of the function.

    instead of “result1=0” add:

    this.result1 = ( this.result1  ) ? this.result1 : 0; // this will make sure it keeps old stored values from last time you call the function.
    

    and change your incrementers to the following:

    this.result1++; // or you can use ++this.result1; or even this.result1+=1;
    

    I hope that answers your question.

    thanks,
    Miter

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to develop an app of HVGA [320 x 480] its showing
I am trying to develop a quiz app for physics, but I keep getting
Trying to develop using MVVM: I have this Csla.PropertyStatus control that is created in
I am trying to develop a mail trigger. Could someone assist on how this
im trying to develop a social networking application and im having some trouble showing
Im trying to develop a simple java code which will upload some contents from
I trying to develop a game for iPhone by using Cocos2d. I need 'DRAG'
I am trying develop a basic referrer system to my Django website, system will
Im trying to develop service that starts by bootup receiver if the wifi or
Im trying to develop my first ASP.NET MVC web app and have run into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.