You need to sign in to do that
Don't have an account?
"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.
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.
In your component, try changing your totalValue provider to:
Then substitute your entire if/else statement with:
LMK if that helps!
Jeff Douglas
Trailhead Developer Advocate
All Answers
In your component, try changing your totalValue provider to:
Then substitute your entire if/else statement with:
LMK if that helps!
Jeff Douglas
Trailhead Developer Advocate
I had the exact same problem, the component was functioning as the challenge stated, but still not passing.