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 6628081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:05:21+00:00 2026-05-25T22:05:21+00:00

Thanks for taking time to review this question. I’ve been trying to fix a

  • 0

Thanks for taking time to review this question. I’ve been trying to fix a problem for one or two hours with no success…

I have a web page that sets a JavaScript variable based on the response from a function:

grade = getScore(questionAnswer, userAnswer, questionType);

(userAnswer is the user’s answer to a question and is retrieved from a textarea)

Here is getScore:

function getScore(questionAnswer, userAnswer, questionType) {

    switch(questionType) {
        case 'multiplechoice':
            return scoreMC(questionAnswer, userAnswer);
        break;

        case 'usertypesanswer':
            return scoreTA(questionAnswer, userAnswer);         
        break;

        default:
            return 0
    }   

}

The functions for scoreMC and scoreTA have been tested thoroughly and work great. The issue is that if a user’s answer is not formatted correctly, scoreMC or scoreTA will return false. Otherwise it returns the values score and msg. However, instead of getting a “false” value for “grade” when I set the value of the grade variable based on the getScore function, I get “undefined”. (We have no problems when the user response validates properly.)

After setting “grade”, I have tried to check if any part of it is undefined:

if(typeof(grade.score) !== undefined)

I do not understand why, but even when I see “undefined” in my Firebug console, grade.score passes this check…

Does anyone see what I am doing wrong? Thank you very much for your assistance. I have a lot to learn about JavaScript.

  • 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-05-25T22:05:22+00:00Added an answer on May 25, 2026 at 10:05 pm
    if(typeof(grade.score) !== undefined)
    

    can be

    if(grade.score && grade.score !== false) // if I understand your question 
    

    or

    if(typeof(grade.score) !== "undefined")
    

    typeof returns a string

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

Sidebar

Related Questions

Thanks for taking time to read this question. I am designing a 3-tier solution
thanks for taking the time out to read this post. I'm having trouble trying
Problem: Thanks for taking the time to read this. I'm having a problem which
Hi there and thanks for taking the time for this question. I'm using a
First of all, thanks for taking the time to read this. I've been working
Thanks for taking the time to read this. I have an unknown number of
thanks for taking the time to stop by my question. Below you will find
First of all thanks for taking the time to look into this. I store
Firstly, thanks for taking the time to read this and possibly comment on it.
Thanks everyone for taking the time to read this. I have styled my navigation

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.