-3
var num=1234 

My answer should be 4 how do i do that? I tried using "split" and "toString" but I don't know how to use it.

1

3 Answers 3

1

Do you need to use toString and split? Because the most efficient way is num % 10

Sign up to request clarification or add additional context in comments.

2 Comments

thnks it works so i do num%10 and it gives me the last digit
but it doesnt work on huge numbers i need it to work on any number
1

Working Example

var lastNum = num.toString().split('').pop(); 

Comments

1

Try this

var num = 1234; var stringNum = num.toString(); var arrayNum = stringNum.split(""); var lastNumber = arrayNum[arrayNum.length-1]; 

2 Comments

<script> function div (num) { function div (num) { var nums = num; var stringNum = num.toString(); var arrayNum = stringNum.split(""); var lastNumber = arrayNum[arrayNum.length-1]; return lastNumber; } document.write (div(5555555555555555555555557)) </script>
"My answer should be 4 how do i do that? I tried using "split" and "toString" but I don't know how to use it." that is what he want

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.