function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ben MyhreBen Myhre 

"Using JavaScript Controllers With Components " is working as I anticipate, but the challenge is saying something is wrong. What is it.

Developer Intermediate > Lightning Components > Using JavaScript Controllers With Components

Here is the Component:

<aura:component >
    <aura:attribute name="total" type="Integer" default="0"/>
    <ui:inputNumber aura:id="inputOne" label="Enter 1"/>
    <ui:inputNumber aura:id="inputTwo" label="Enter 2"/>
    <ui:inputNumber aura:id="inputThree" label="Enter 3"/>
    
    <ui:button label="Submit" press="{!c.calculate}"/>
    <ui:outputNumber aura:id="totalValue" value="{!v.total}"/>
</aura:component>

Here is the Controller:

({
    calculate : function(component, event, helper) {
        var inputOne = parseInt(component.find("inputOne").get("v.value"));

        var inputTwo = parseInt(component.find("inputTwo").get("v.value"));
        var inputThree = parseInt(component.find("inputThree").get("v.value"));
        var total = inputOne + inputTwo - inputThree;
        if (isNaN(total)){
            component.set("v.errors", [{message:"Total not a number: " + total}]);
        } else {
            component.set("v.total", total);
        }
    }
})

The error it gives me is "Challenge Not yet complete... here's what's wrong: 
The client side controller does not set a value for the outputNumber component".... BUT based on when I plig this into an app and run it, it sure appeas that the value for outputNumber is being set.

Any help would be appreciated.
Best Answer chosen by Ben Myhre
Jeff DouglasJeff Douglas
Ben, you are right. Your solution works for your case. We are just checking for some specific code.

In your component, try changing your totalValue provider to:
<ui:outputNumber aura:id="totalValue" value="" />

Then substitute your entire if/else statement with:
component.find("totalValue").set("v.value",total);

LMK if that helps!

Jeff Douglas
Trailhead Developer Advocate

All Answers

Jeff DouglasJeff Douglas
Ben, you are right. Your solution works for your case. We are just checking for some specific code.

In your component, try changing your totalValue provider to:
<ui:outputNumber aura:id="totalValue" value="" />

Then substitute your entire if/else statement with:
component.find("totalValue").set("v.value",total);

LMK if that helps!

Jeff Douglas
Trailhead Developer Advocate
This was selected as the best answer
Ben MyhreBen Myhre
That worked! Thank you a gajabillion.
Tyler ZikaTyler Zika
May I suggest in the tutorial to mention: DO NOT use an aura attribute? That way it would force us to go about it challenge in the way it was intended.

I had the exact same problem, the component was functioning as the challenge stated, but still not passing.