Hi, i want to increase/decrease the text with an button, I tried searching js examples on internet but not work. Can anyone help me?
“+” increase “0”
“-” decrease “0”
“0” = “text1”
“-” = “button1”
“+” = “button2”
Hi, i want to increase/decrease the text with an button, I tried searching js examples on internet but not work. Can anyone help me?
“+” increase “0”
“-” decrease “0”
“0” = “text1”
“-” = “button1”
“+” = “button2”
Hi,
If you would like to code what happens to the text that is displayed in “text1” after the + or - buttons are clicked, I suggest taking a look at the onClick() function for the button element here . You will want to set the onClick function for each button.
When you write some code that increments or decrements the value that is being shown in “text1” you will want to set the new value shown in the text element by using the .text property as it shows in the example shown the Corvid API reference here .
Best regards,
Edward | Corvid Team
I really don’t know how to program and what I would like to happen when clicking on the “+” button, the “text1” will add up the value, ex:
text1 = 0
button2 onClick, text1 = 1
button2 onClick, text1 = 2
button2 onClick, text1 = 3
…
Hello Jean,
you can create a function which will do the maths for you.
Take a look at this example…
https://russian-dima.wixsite.com/meinewebsite/simple-return-function
So you can create different types of functions (sum / mulstiplicate / and so on…)
Like these, but I need to increase like “i++”
Take a look one more time…
https://russian-dima.wixsite.com/meinewebsite/simple-return-function
var COUNTER = 0
function count_up () {
COUNTER = COUNTER+1
console.log(COUNTER)
return COUNTER
}
var COUNTER2 = 10
function count_down () {
COUNTER2 = COUNTER2-1
console.log(COUNTER2)
return COUNTER2
}
export function BTNcountup_click(event) {
let myNewButtonLabel = count_up()
$w('#BTNcountup').label = myNewButtonLabel.toString()
}
export function BTNcountdown_click(event) {
let myNewButtonLabel = count_down()
$w('#BTNcountdown').label = myNewButtonLabel.toString()
}
You can also work without “RETURN”.
Perfect, I edited your code and achieved exactly what I needed, thank you so much for your support !!
var COUNTER = 0
function count_up () {
COUNTER = COUNTER+1
console.log(COUNTER)
return COUNTER
}
function count_down () {
COUNTER = COUNTER-1
console.log(COUNTER)
return COUNTER
}
export function button2_click(event) {
let myNewTextLabel = count_up()
$w('#text1').text = myNewTextLabel.toString()
}
export function button1_click(event) {
let myNewTextLabel = count_down()
$w('#text1').text = myNewTextLabel.toString()
}
Thank you all for your support and attention!
No problem, you are welcome.
You can lieke it, if you liked it