Posts

Showing posts from August, 2021

Posting Data on Mailchimp Server and redirecting based on success rate of Post Data

  const   express   =   require ( "express" ); const   https   =   require ( 'https' ); const  mailchimp  =   require ( "@mailchimp/mailchimp_marketing" ); // MailChimp API key mailchimp. setConfig ({   apiKey:  "3574780b3b1a31ae322ec0c4e9c08729-us5" ,   server:  "us5" , }); // MailChimp Audience List ID for the Newsletter const  listID  =   "74a14fa783" ; // Start express application const  app  =   express (); // This line defines a static directory for local resources app. use ( express . static ( "public" )); // body-parser is deprecated, using this instead app. use ( express . urlencoded ({extended:  true })); // When page loads, display signup.html app. get ( "/" ,  function ( req ,  res ) {...

Weather Api Form(HTML)

 <!DOCTYPE html> <html lang="en" dir="ltr">   <head>     <meta charset="utf-8">     <title>Weather App</title>   </head>   <body>     <form action="/" method="post">       <label for="city">City Name:</label>       <input id="city" name="cityName"type="text">       <button type="submit" name="button">Go</button>     </form>   </body> </html>

Weather Api incorporation to our website (Express)

// Requiring and bindingExpress const express=require("express"); const app=express(); //Requiring Body-parser const bodyParser=require("body-parser"); // Requirng Https const https= require("https"); //Using Body-parser with express app.use(bodyParser.urlencoded({extended:true})); // Get request using Express app.get("/",(req,res)=>{   res.sendFile(__dirname+"/index.html") }); app.post("/",(req,res)=>{     console.log();     // Incororating API Endpoint     const appKey = "d482678f9db290646f15671a90add5ee";     const query = req.body.cityName;     const unit="metric";     const url= "https://api.openweathermap.org/data/2.5/weather?q="+query+"&appid="+appKey+"&units="+unit;     // Get request using HTTPS     https.get(url,(response)=>{       // Capturing data from the end point using on method       response.on("data",(data)=>{       ...

Simon game CSS

 body {   text-align: center;   background-color: #011F3F; } #level-title {   font-family: 'Press Start 2P', cursive;   font-size: 3rem;   margin:  5%;   color: #FEF2BF; } .container {   display: block;   width: 50%;   margin: auto; } .btn {   margin: 25px;   display: inline-block;   height: 200px;   width: 200px;   border: 10px solid black;   border-radius: 20%; } .game-over {   background-color: red;   opacity: 0.8; } .red {   background-color: red; } .green {   background-color: green; } .blue {   background-color: blue; } .yellow {   background-color: yellow; } .pressed {   box-shadow: 0 0 20px white;   background-color: grey; }

Simon Game HTML

 <!DOCTYPE html> <html lang="en" dir="ltr"> <head>   <meta charset="utf-8">   <title>Simon</title>   <link rel="stylesheet" href="styles.css">   <link href="https://fonts.googleapis.com/css?family=Press+Start+2P" rel="stylesheet"> </head> <body>   <h1 id="level-title">Press A Key to Start</h1>   <div class="container">     <div lass="row">       <div type="button" id="green" class="btn green">       </div>       <div type="button" id="red" class="btn red">       </div>     </div>     <div class="row">       <div type="button" id="yellow" class="btn yellow">       </div>       <div type="button" id="blue" class="btn blue">   ...

Simon Game Java Script

  var buttonColours = ["red", "blue", "green", "yellow"]; var gamePattern = []; var userClickedPattern = []; var started = false; var level = 0; $(document).keypress(function() {   if (!started) {     $("#level-title").text("Level " + level);     nextSequence();     started = true;   } }); $(".btn").click(function() {   var userChosenColour = $(this).attr("id");   userClickedPattern.push(userChosenColour);   playSound(userChosenColour);   animatePress(userChosenColour);   checkAnswer(userClickedPattern.length-1); }); function checkAnswer(currentLevel) {     if (gamePattern[currentLevel] === userClickedPattern[currentLevel]) {       if (userClickedPattern.length === gamePattern.length){         setTimeout(function () {           nextSequence();         }, 1000);       }     } else {       pl...

Bmi calculator using body parser in express (node.js)

  const   express   =   require ( "express" ); const  app = express (); const   bodyParser   =   require ( "body-parser" ); app. use ( bodyParser . urlencoded ({extended: true })); // Calculator app. get ( "/" , function ( req , res ){      res . sendFile (__dirname  + "/index.html" ); }); app. post ( "/" , function ( req , res ){      var  num1 = Number ( req .body.n1);      var  num2 = Number ( req .body.n2);      var  result = num1 + num2;      res . send ( "the result is:" + result); }) // BMI app. get ( "/bmiCalculator" , function ( req , res ){      res . sendFile (__dirname + "/bmiCalculator.html" ); }); app. post ( "/bmiCalculator" , function ( req , res ){      var  height = Number ( req .body.height);      var  weight = Number ( re...