{"id":988,"date":"2023-08-30T09:34:25","date_gmt":"2023-08-30T09:34:25","guid":{"rendered":"https:\/\/www.devopsfreelancer.com\/blog\/?p=988"},"modified":"2023-08-30T09:34:27","modified_gmt":"2023-08-30T09:34:27","slug":"how-to-use-prompt-function-in-javascript","status":"publish","type":"post","link":"https:\/\/www.devopsfreelancer.com\/blog\/how-to-use-prompt-function-in-javascript\/","title":{"rendered":"How to use Prompt function in JavaScript ?"},"content":{"rendered":"\n<p>In this tutorial we&#8217;re going to learn how to use Prompt function using JavaScript. <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>let age = prompt(\"What is your age?\", 18);<\/code>&nbsp;&#8211; This line of code uses the&nbsp;<code>prompt()<\/code>&nbsp;function to prompt the user for their age. The second argument, 18, is the default age if the user does not enter anything.<\/li>\n\n\n\n<li><code>let welcome = (age &lt; 18) ? () =&gt; alert('Hello!') : () =&gt; alert(\"Greetings!\");<\/code>&nbsp;&#8211; This line of code creates a variable called&nbsp;<code>welcome<\/code>&nbsp;and assigns it an anonymous function. The anonymous function takes one argument,&nbsp;<code>age<\/code>, and returns a function that displays a message. The&nbsp;<code>age &lt; 18<\/code>&nbsp;expression inside the&nbsp;<code>?<\/code>&nbsp;ternary operator checks if the user&#8217;s age is less than 18. If it is, the first function is returned. Otherwise, the second function is returned.<\/li>\n\n\n\n<li><code>welcome();<\/code>&nbsp;&#8211; This line of code calls the&nbsp;<code>welcome()<\/code>&nbsp;function. This function will display the message &#8220;Hello!&#8221; if the user&#8217;s age is less than 18, or the message &#8220;Greetings!&#8221; if the user&#8217;s age is 18 or older.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Just use below code and put put inside the script tag<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>let age = prompt(\"What is your age?\", 18);\r\nlet welcome = (age &lt; 18) ?\r\n    () => alert('Hello!') :\r\n    () => alert(\"Greetings!\");\r\n\r\nwelcome();<\/code><\/pre>\n\n\n\n<p><strong>Output:- <\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"276\" src=\"https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/08\/image-105-1024x276.png\" alt=\"\" class=\"wp-image-989\" srcset=\"https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/08\/image-105-1024x276.png 1024w, https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/08\/image-105-300x81.png 300w, https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/08\/image-105-768x207.png 768w, https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/08\/image-105.png 1356w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>I hope its helpful for you \ud83d\udc4d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial we&#8217;re going to learn how to use Prompt function using JavaScript. Just use below code and put put inside the script tag Output:- I&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[199],"tags":[402,22,400,401],"class_list":["post-988","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-how-to-use-prompt-function","tag-javascript","tag-prompt","tag-prompt-function-javascript"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to use Prompt function in JavaScript ? - DevOps Freelancer<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.devopsfreelancer.com\/blog\/how-to-use-prompt-function-in-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to use Prompt function in JavaScript ? - DevOps Freelancer\" \/>\n<meta property=\"og:description\" content=\"In this tutorial we&#8217;re going to learn how to use Prompt function using JavaScript. Just use below code and put put inside the script tag Output:- I...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.devopsfreelancer.com\/blog\/how-to-use-prompt-function-in-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"DevOps Freelancer\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/amitsthakurs\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-30T09:34:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-30T09:34:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/08\/image-105-1024x276.png\" \/>\n<meta name=\"author\" content=\"Amit Kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/amits_thakurs\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Amit Kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/how-to-use-prompt-function-in-javascript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/how-to-use-prompt-function-in-javascript\\\/\"},\"author\":{\"name\":\"Amit Kumar\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/#\\\/schema\\\/person\\\/22ed4bd82dc04200a2ca541b3e35fc5b\"},\"headline\":\"How to use Prompt function in JavaScript ?\",\"datePublished\":\"2023-08-30T09:34:25+00:00\",\"dateModified\":\"2023-08-30T09:34:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/how-to-use-prompt-function-in-javascript\\\/\"},\"wordCount\":177,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/how-to-use-prompt-function-in-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/image-105-1024x276.png\",\"keywords\":[\"how-to-use-prompt-function\",\"javascript\",\"prompt\",\"prompt-function-javascript\"],\"articleSection\":[\"Javascript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/how-to-use-prompt-function-in-javascript\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/how-to-use-prompt-function-in-javascript\\\/\",\"url\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/how-to-use-prompt-function-in-javascript\\\/\",\"name\":\"How to use Prompt function in JavaScript ? - DevOps Freelancer\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/how-to-use-prompt-function-in-javascript\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/how-to-use-prompt-function-in-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/image-105-1024x276.png\",\"datePublished\":\"2023-08-30T09:34:25+00:00\",\"dateModified\":\"2023-08-30T09:34:27+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/#\\\/schema\\\/person\\\/22ed4bd82dc04200a2ca541b3e35fc5b\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/how-to-use-prompt-function-in-javascript\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/how-to-use-prompt-function-in-javascript\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/how-to-use-prompt-function-in-javascript\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/image-105.png\",\"contentUrl\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/image-105.png\",\"width\":1356,\"height\":366},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/how-to-use-prompt-function-in-javascript\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to use Prompt function in JavaScript ?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/\",\"name\":\"DevOps Freelancer\",\"description\":\"We provide DevOps | SRE | DevSecOps | MLOps Freelancing\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/#\\\/schema\\\/person\\\/22ed4bd82dc04200a2ca541b3e35fc5b\",\"name\":\"Amit Kumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d76fb4d0f15f7a458f1fd91063b44fbb7e7eb9e724b1c465d885054c2540250f?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d76fb4d0f15f7a458f1fd91063b44fbb7e7eb9e724b1c465d885054c2540250f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d76fb4d0f15f7a458f1fd91063b44fbb7e7eb9e724b1c465d885054c2540250f?s=96&d=mm&r=g\",\"caption\":\"Amit Kumar\"},\"description\":\"Hi I am Amit Kumar Thakur Experienced as s Software Developer with a demonstrated history of working in the information technology and services industry. Skilled in HTML, CSS, Bootstrap4, PHP, Laravel-9 , REST API,FB API,Google API, Youtube Api, Bitbucket,Github,Linux and jQuery. Strong engineering professional focused in Computer\\\/Information Technology Administration and Management. Currently my profile is to Software Developer, analyze the requirement, creating frame for web application, coding and maintenance.\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/amitsthakurs\\\/\",\"https:\\\/\\\/www.instagram.com\\\/amits_thakurs\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/amits-thakurs\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/amits_thakurs\"],\"url\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/author\\\/amit\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to use Prompt function in JavaScript ? - DevOps Freelancer","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.devopsfreelancer.com\/blog\/how-to-use-prompt-function-in-javascript\/","og_locale":"en_US","og_type":"article","og_title":"How to use Prompt function in JavaScript ? - DevOps Freelancer","og_description":"In this tutorial we&#8217;re going to learn how to use Prompt function using JavaScript. Just use below code and put put inside the script tag Output:- I...","og_url":"https:\/\/www.devopsfreelancer.com\/blog\/how-to-use-prompt-function-in-javascript\/","og_site_name":"DevOps Freelancer","article_author":"https:\/\/www.facebook.com\/amitsthakurs\/","article_published_time":"2023-08-30T09:34:25+00:00","article_modified_time":"2023-08-30T09:34:27+00:00","og_image":[{"url":"https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/08\/image-105-1024x276.png","type":"","width":"","height":""}],"author":"Amit Kumar","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/amits_thakurs","twitter_misc":{"Written by":"Amit Kumar","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.devopsfreelancer.com\/blog\/how-to-use-prompt-function-in-javascript\/#article","isPartOf":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/how-to-use-prompt-function-in-javascript\/"},"author":{"name":"Amit Kumar","@id":"https:\/\/www.devopsfreelancer.com\/blog\/#\/schema\/person\/22ed4bd82dc04200a2ca541b3e35fc5b"},"headline":"How to use Prompt function in JavaScript ?","datePublished":"2023-08-30T09:34:25+00:00","dateModified":"2023-08-30T09:34:27+00:00","mainEntityOfPage":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/how-to-use-prompt-function-in-javascript\/"},"wordCount":177,"commentCount":0,"image":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/how-to-use-prompt-function-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/08\/image-105-1024x276.png","keywords":["how-to-use-prompt-function","javascript","prompt","prompt-function-javascript"],"articleSection":["Javascript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.devopsfreelancer.com\/blog\/how-to-use-prompt-function-in-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.devopsfreelancer.com\/blog\/how-to-use-prompt-function-in-javascript\/","url":"https:\/\/www.devopsfreelancer.com\/blog\/how-to-use-prompt-function-in-javascript\/","name":"How to use Prompt function in JavaScript ? - DevOps Freelancer","isPartOf":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/how-to-use-prompt-function-in-javascript\/#primaryimage"},"image":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/how-to-use-prompt-function-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/08\/image-105-1024x276.png","datePublished":"2023-08-30T09:34:25+00:00","dateModified":"2023-08-30T09:34:27+00:00","author":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/#\/schema\/person\/22ed4bd82dc04200a2ca541b3e35fc5b"},"breadcrumb":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/how-to-use-prompt-function-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.devopsfreelancer.com\/blog\/how-to-use-prompt-function-in-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.devopsfreelancer.com\/blog\/how-to-use-prompt-function-in-javascript\/#primaryimage","url":"https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/08\/image-105.png","contentUrl":"https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/08\/image-105.png","width":1356,"height":366},{"@type":"BreadcrumbList","@id":"https:\/\/www.devopsfreelancer.com\/blog\/how-to-use-prompt-function-in-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.devopsfreelancer.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to use Prompt function in JavaScript ?"}]},{"@type":"WebSite","@id":"https:\/\/www.devopsfreelancer.com\/blog\/#website","url":"https:\/\/www.devopsfreelancer.com\/blog\/","name":"DevOps Freelancer","description":"We provide DevOps | SRE | DevSecOps | MLOps Freelancing","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.devopsfreelancer.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.devopsfreelancer.com\/blog\/#\/schema\/person\/22ed4bd82dc04200a2ca541b3e35fc5b","name":"Amit Kumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d76fb4d0f15f7a458f1fd91063b44fbb7e7eb9e724b1c465d885054c2540250f?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d76fb4d0f15f7a458f1fd91063b44fbb7e7eb9e724b1c465d885054c2540250f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d76fb4d0f15f7a458f1fd91063b44fbb7e7eb9e724b1c465d885054c2540250f?s=96&d=mm&r=g","caption":"Amit Kumar"},"description":"Hi I am Amit Kumar Thakur Experienced as s Software Developer with a demonstrated history of working in the information technology and services industry. Skilled in HTML, CSS, Bootstrap4, PHP, Laravel-9 , REST API,FB API,Google API, Youtube Api, Bitbucket,Github,Linux and jQuery. Strong engineering professional focused in Computer\/Information Technology Administration and Management. Currently my profile is to Software Developer, analyze the requirement, creating frame for web application, coding and maintenance.","sameAs":["https:\/\/www.facebook.com\/amitsthakurs\/","https:\/\/www.instagram.com\/amits_thakurs\/","https:\/\/www.linkedin.com\/in\/amits-thakurs\/","https:\/\/x.com\/https:\/\/twitter.com\/amits_thakurs"],"url":"https:\/\/www.devopsfreelancer.com\/blog\/author\/amit\/"}]}},"_links":{"self":[{"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/posts\/988","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/comments?post=988"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/posts\/988\/revisions"}],"predecessor-version":[{"id":990,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/posts\/988\/revisions\/990"}],"wp:attachment":[{"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/media?parent=988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/categories?post=988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/tags?post=988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}