+ 3

How to get Value of Button

I am trying to create a calculator. I want whenever we clicked to button it have to show in that black screen our clicked value.Below I will attach my code https://code.sololearn.com/WxSVt7SKpTnN/?ref=app

16th Mar 2020, 11:34 PM
Abdulaziz Abdurasul
Abdulaziz Abdurasul - avatar
5 ответов
+ 2
Something to keep in mind. When you use getElementsByClassName you are asking a collection of elements, so when you try to get an individual elements value you need to state which element you are referring to, in most case it is the first element at the 0 index. So... document.getElementsByClassName('btn-one').value; <-- don't do this. document.getElementsByClassName('btn-one')[0].value;<-- do this.
17th Mar 2020, 12:20 AM
ODLNT
ODLNT - avatar
+ 1
Still its confusing to me because I new to JavaScript I just finished html css and I finished only the basics of JavaScript ((
17th Mar 2020, 12:33 AM
Abdulaziz Abdurasul
Abdulaziz Abdurasul - avatar
+ 1
ODLNT onclick to button i want to get the number which it is presenting and store it in a variable then print it to the screen 😣
17th Mar 2020, 1:01 AM
Abdulaziz Abdurasul
Abdulaziz Abdurasul - avatar
0
Javascript can be confusing. What exactly is confusing you at this moment?
17th Mar 2020, 12:51 AM
ODLNT
ODLNT - avatar
0
Now I must admit I am somewhat confused. What you are trying to do with the calculator is no different than what you have done with your card project (getPrice() function). You should follow that same concept.
17th Mar 2020, 1:11 AM
ODLNT
ODLNT - avatar