Javascript_ user.js中的错误TypeError:无法读取未定义的属性“value”

时间:2017-02-01 14:53:53

标签: javascript articulate-storyline

这是一些问题。 我想问你如何应对这个问题?其实我是Javascript的新手。 提前谢谢。

在控制台上看起来像这样:

  

Javascript_ user.js中的错误TypeError:无法读取未定义的属性“value”

function checkPassword(form) {
  var password = checkPassword(password);
  var s_letters = "qwertyuiopasdfghjklzxcvbnm"; 
  var b_letters = "QWERTYUIOPLKJHGFDSAZXCVBNM"; 
  var digits = "0123456789"; 
  var specials = "!@#$%^&*()_-+=\|/.,:;[]{}"; 
  var is_s = false; 
  var is_b = false;
  var is_d = false; 
  var is_sp = false; 

  for (var i = 0; i < password.length; i++) {
    if (!is_s && s_letters.indexOf(password[i]) != -1) is_s = true;
    else if (!is_b && b_letters.indexOf(password[i]) != -1) is_b = true;
    else if (!is_d && digits.indexOf(password[i]) != -1) is_d = true;
    else if (!is_sp && specials.indexOf(password[i]) != -1) is_sp = true;
  }

  var rating = 0;
  var text = "";
  if (is_s) rating++; 
  if (is_b) rating++; // 
  if (is_d) rating++; // 
  if (is_sp) rating++; // 
  if (password.length < 6 && rating < 3) text = "Bad";
  else if (password.length < 6 && rating >= 3) text = "Good";
  else if (password.length >= 8 && rating < 3) text = "Good";
  else if (password.length >= 8 && rating >= 3) text = "Excellent";
  else if (password.length >= 6 && rating == 1) text = "Bad";
  else if (password.length >= 6 && rating > 1 && rating < 4) text = "Good";
  else if (password.length >= 6 && rating == 4) text = "Excellent";
  console.log(text); // Alert will not work for us here. Console.log allows you to export data to the console for troubleshooting.
  return text;
}

var player = GetPlayer(); // Gets the player object.
var myPassword = player.GetVar("SystemDate"); // Gets the value for myPassword
console.log(myPassword);
var newValue = checkPassword(myPassword); // Run the function and return to newValue
player.SetVar("SystemDate",newValue); // Set the value of newValue back to Storyline

1 个答案:

答案 0 :(得分:0)

我稍微改变了你的功能,尝试一下(并显示我们SetValue功能):

// @first error - password input, not the form
function checkPassword (password) {
    var expr, 
        rating = 0, 
        rules = {
            // Lower case
            '/[a-z]+/g': false,
            // Upper case
            '/[A-Z]+/g': false,
            // Numbers
            '/[0-9]+/g': false,
            // Special symbols
            '/[^\w\s]/gi': false
        };

    for (expr in rules) {
        if (password.match(expr)) {
            // rules[expr] = true; // - can be used to show the proper message of invalidation
            rating++;
        }
    }

    return 
        || password.length >= 8 && rating >= 3 && "Excellent"
        || password.length < 6 && rating >= 3 && "Good"
        || password.length >= 8 && rating < 3 && "Good"
        || password.length >= 6 && rating > 1 && rating < 4 && "Good"
        || "Bad";
}

// Gets the player object.
var player = GetPlayer(); 
// Gets the value for myPassword
var myPassword = player.GetVar("SystemDate"); 
// Run the function and return to newValue
var newValue = checkPassword(myPassword); 
// Set the value of newValue back to Storyline
// @second error seems to be in the function SetVar
player.SetVar("SystemDate",newValue);