From eb5e60ad63adb59969a4719e15545152ca6dd0c1 Mon Sep 17 00:00:00 2001 From: Pranayee35 Date: Mon, 27 Oct 2025 14:32:11 +0530 Subject: [PATCH] added input validation to greet() function --- JavaScript Programs Using Functions/question2.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/JavaScript Programs Using Functions/question2.js b/JavaScript Programs Using Functions/question2.js index 8679d5a..4301e93 100644 --- a/JavaScript Programs Using Functions/question2.js +++ b/JavaScript Programs Using Functions/question2.js @@ -2,11 +2,15 @@ // program to print the text // declaring a function function greet(name) { - console.log("Hello " + name + ":)"); + if (!name) { + console.log("You didn't enter your name!"); + } else { + console.log(`Hello ${name} 😊`); + } } // variable name can be different -let name = prompt("Enter a name: "); +let name = prompt("Enter your name:"); // calling function -greet(name); \ No newline at end of file +greet(name);