-1

I am new on Javascript. I was asked to write a program that prompts the user to enter a number between 0-9. The program should log the number in words.

const input = require('readline-sync');

let num1 = input.question("Enter a number between 0-9: ");
let a = num1.toString()

console.log(num1.toString)

What am I doing wrong ?

Rudra
  • 1,678
  • 16
  • 29

2 Answers2

0

when you call toString you are trying to print the function, you need to invoke the function toString() to be able to print its returned value.


const input = require('readline-sync');

let num1 = input.question("Enter a number between 0-9: "); 

let a = num1.toString()

console.log(num1.toString())

Marik Ishtar
  • 2,899
  • 1
  • 13
  • 27
0

Like this ?

function myFunction(){
  var x = document.getElementById("username").value;
  console.log(x.toString());
}
button{
  background:#0095ff;
  outline:noene;
  padding:10px;
  border:none;
  border-radius:5px;
  margin-top:10px;
}
<form>
  <label for="username">Enter Number:</label><br>
  <input type="number" id="username" name="username"><br>
</form>

<button onclick="myFunction()">Try it</button>
Rohit Tagadiya
  • 3,373
  • 1
  • 25
  • 25