Javascript excercise: Create a new html file. Give provision for users to insert a number (you can use prompt boxes or text fields). If the user inserts a number, show the multiplication table for that number in console log. But, if the user inserts anything other than a number, show appropriate error messages.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
</head>
<body>
<script>
const n = prompt('Enter number:');
if (n.replace(/\s/g, '').length === 0 || isNaN(n)) {
console.log('Wrong number');
} else {
for (let i = 1; i <= 10; i++) {
console.log(`${n} * ${i} = ${n*i}`)
}
}
</script>
</body>
</html>
Comments
Leave a comment