Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to solve null error

Community Beginner ,
Jul 26, 2018 Jul 26, 2018

Program is to turn standard time to traditional time. Ex 24:23 is 12:23. But instead of that when I run the the program is just gives me null.

// Name:

// Date:

// Purpose: To convert standard time to traditional time

// This line makes the button, btnConvert wait for a mouse click

// When the button is clicked, the convertTime function is called

btnConvert.addEventListener(MouseEvent.CLICK, convertTime);

// This line makes the textinput wait for a mouse click

// When this component is clicked, the clearLabels function is called

txtinStandard.addEventListener(MouseEvent.CLICK, clearLabels);

// Declare Global Variables

var traditionalTime:String;    // traditional time

// This is the convertTime function

// e:MouseEvent is the click event experienced by the button

// void indicates that the function does not return a value

function convertTime(e:MouseEvent):void

{

// declare the variables

var standardTime:String;    // standard time entered by user

standardTime = txtinStandard.text;     // get standard time from user

convertToTraditional(standardTime);    // call the convertToTraditional function

// output an appropriate message in the label

lblOutput.text = standardTime + " is equivalent to " + traditionalTime;

}

// This is function convertToTraditional

// s – is the standard time

// It determines the traditional time based on the value of s

function convertToTraditional(s:String){

// write the code here

if (s == 0){

lblOutput.text += 12;

}

else if (s == "1"){

lblOutput.text += "1";

}

else if (s == "2"){

lblOutput.text += "2";

}

    else if (s == "3"){

lblOutput.text += "3";

}

else if (s == "4"){

lblOutput.text += "4";

}

else if (s == "5"){

lblOutput.text += "5";

}

else if (s == "6"){

lblOutput.text += "6";

}

else if (s == "7"){

lblOutput.text += "7";

}

else if (s == "8"){

lblOutput.text += "8";

}

else if (s == "9"){

lblOutput.text += "9";

}

else if (s == "10"){

lblOutput.text += "10";

}

else if (s == "11"){

lblOutput.text += "11";

}

else if (s == "12"){

lblOutput.text += "12";

}

else if (s == "13"){

lblOutput.text += "1";

}

else if (s == "14"){

lblOutput.text += "2";

}

else if (s == "15"){

lblOutput.text += "3";

}

else if  (s == "16"){

lblOutput.text += "4";

}

else if (s == "17"){

lblOutput.text += "5";

}

else if (s == "18"){

lblOutput.text += "6";

}

else if  (s == "19"){

lblOutput.text += "7";

}

else if  (s == "20"){

lblOutput.text += "8";

}

else if (s == "21"){

lblOutput.text += "9";

}

else if (s == "22"){

lblOutput.text += "10";

}

else if (s == "23"){

lblOutput.text += "11";

}

else if (s == "24"){

lblOutput.text += "12";

}

}

// This is the clearLabels function

// e:MouseEvent is the click event experienced by the textInput

// void indicates that the function does not return a value

function clearLabels(e:MouseEvent):void

{

     lblOutput.text = "";

txtinStandard.text = "";

}

517
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 26, 2018 Jul 26, 2018

the problematic line number will be in the error message allowing you to quickly pinpoint your error, or post it (error msg and line of code) here for help.

Translate
Community Expert ,
Jul 26, 2018 Jul 26, 2018

for the 3rd time, tick 'permit debugging'

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 26, 2018 Jul 26, 2018

went on file, clicked published settings, then you said to click permit debugging. Clicked that and nothing happened.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 26, 2018 Jul 26, 2018

I can't believe I'm being goaded into doing your homework for you again, but just so you know, that entire ~80-line function can be replaced with this:

function convertToTraditional(s:String) {

    var n:Number = Number(s) % 12;

    return n ? n : 12;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 26, 2018 Jul 26, 2018

he's going to fail using if he uses either of our code snippets because it's going to be obvious to the instructor that he didn't create those snippets himself.

we should force him to correct his own code using his own ideas (which i think he's done for the most part with his verbose solutions).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 26, 2018 Jul 26, 2018

i still got null

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 26, 2018 Jul 26, 2018
LATEST

the problematic line number will be in the error message allowing you to quickly pinpoint your error, or post it (error msg and line of code) here for help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines