{"id":3056,"date":"2021-08-01T13:20:38","date_gmt":"2021-08-01T13:20:38","guid":{"rendered":"https:\/\/rengga.dev\/blog\/?p=3056"},"modified":"2023-02-28T01:04:33","modified_gmt":"2023-02-28T01:04:33","slug":"js-tutorial-math-random-display-a-random-image","status":"publish","type":"post","link":"https:\/\/rengga.dev\/blog\/js-tutorial-math-random-display-a-random-image\/","title":{"rendered":"JS Tutorial &#8211; Math.random() Display A Random Image"},"content":{"rendered":"<p><span style=\"color: #ef3207;\"><a style=\"color: #ef3207;\" href=\"https:\/\/rengga.dev\/\" target=\"_blank\" rel=\"noopener\"><strong>Rengga Dev<\/strong><\/a> <\/span>&#8211; <code>Math.random()<\/code>\u00a0is an API in JavaScript. It is a function that gives you a random number. The number returned will be between 0 (inclusive, as in, it\u2019s possible for an actual 0 to be returned) and 1 (exclusive, as in, it\u2019s not possible for an actual 1 to be returned).<br \/>\n<iframe style=\"width: 100%;\" title=\"JS Tutorial - Random Picture Generator\" src=\"https:\/\/codepen.io\/renggagumilar\/embed\/MWVPOXw?default-tab=result&amp;theme-id=dark\" height=\"800\" frameborder=\"no\" scrolling=\"no\" allowfullscreen=\"allowfullscreen\"><br \/>\nSee the Pen <a href=\"https:\/\/codepen.io\/renggagumilar\/pen\/MWVPOXw\"><br \/>\nJS Tutorial &#8211; Random Picture Generator<\/a> by Rengga Gumilar (<a href=\"https:\/\/codepen.io\/renggagumilar\">@renggagumilar<\/a>)<br \/>\non <a href=\"https:\/\/codepen.io\">CodePen<\/a>.<br \/>\n<\/iframe><br \/>\nImages are stored in an array. A number is generated and multiplied by the number of images in the array via\u00a0<code>array.length<\/code>. Then\u00a0<code>Math.floor<\/code>\u00a0rounds the value to a round number and sets the image src in the HTML when the page is loaded or the button is clicked.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rengga Dev &#8211; Math.random()\u00a0is an API in JavaScript. It is a function <a class=\"read-more\" href=\"https:\/\/rengga.dev\/blog\/js-tutorial-math-random-display-a-random-image\/\" title=\"JS Tutorial &#8211; Math.random() Display A Random Image\" itemprop=\"url\"><\/a><\/p>\n","protected":false},"author":1,"featured_media":3804,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[277,264,263,274,103,227],"newstopic":[],"class_list":["post-3056","post","type-post","status-publish","format-standard","has-post-thumbnail","category-javascript","tag-display-a-random-image","tag-javascript-tutorial","tag-js-tutorial","tag-math-random","tag-web-design","tag-web-designer"],"_links":{"self":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/3056","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/comments?post=3056"}],"version-history":[{"count":1,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/3056\/revisions"}],"predecessor-version":[{"id":3058,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/3056\/revisions\/3058"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/media\/3804"}],"wp:attachment":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/media?parent=3056"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/categories?post=3056"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/tags?post=3056"},{"taxonomy":"newstopic","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/newstopic?post=3056"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}