Posts

Showing posts from October, 2020

randomly changing color of tiles

 index.js------------------ import   React   from   'react' ; import   ReactDOM   from   'react-dom' ; import   App   from   './App' ; ReactDOM . render ( < App   /> ,  document . getElementById ( 'msg' )); App.js------------------ import   React , { Component }  from   'react' ; // import NoteTakingApp from './components/noteTakingApp'; // import NoteTakingApp from './components/noteTakingApp'; import   QuessWhat   from   './components/guessWhat' ; import   './assets/StyleApp.css' ; class   App   extends   Component  {       render () {            return (                 < div >                      < QuessWhat   />                 </ div >           );         } } export   default   App ; guessWhat.js----------------- import   React   from   'react' ; // import SingleTile from './tile'; import   '../assets/StyleApp.css' ; // class Pasting extends Component{   //   

Touch me | react

 1) A Tile changes its color continuously every second(fixed interval of time). 2) Tile get stopped on a fixed color after 10 sec(let say red color). 3) Now red color will blink in every sec 4) If we click that tile screen will show  "You have clicked right  tile" before the time out(10s) 5) The counter increased by one value.

creating random colors from 4 colors

 //js const red = "#" + "ff0000"; const blue = "#" + "0000ff"; const green = "#" + "6FFF00"; const yellow = "#" + "ffff00"; const pink = "#" + "ffc0cb"; //generate random number const randomColorGenerated=()=>{   var random = Math.floor(Math.random() * 4) + 1;   //*4 means four numbers not multiplication.   console.log(random);       var newResult = pink;//initiallizing newResult   if (random == 1) {     console.log("first color");     return newResult=yellow;   }    if(random == 2){     console.log("second color");     return newResult=blue;   }   if(random == 3){     console.log("third color");     return newResult=red;   }   else {     console.log("fourth color");     return newResult=green;   } }; const getVal = randomColorGenerated(); console.log("getval is "+ getVal); const element = document.getElementById("msg");  ele

generating random color

 const getMyColor =()=> { let n = (math.random()*0xfffff*1000000).toString(16); return "#" + n.slice(0, 6); } //const red = #ff0000; const result = getMyColor(); const element = document.getElementById('msg'); element.style.color = result; console. log(result); //in HTML <div> <p id="msg"> Hi, How's you doin? </p> </div>

digital clock using javascript

 <div id="clock"></div> <script type="text/javascript"> setInterval(displayclock, 500); function displayclock(){ var time = new Date(); var hrs = time.getHours(); var min = time.getMinutes(); var sec = time.getSeconds(); if(hrs>12){ hrs = hrs -12; } if(hrs==0){ hrs =12; } //if the digit is less than 10 then it will  show the number with 0 in prefix if(hrs<10){ hrs = '0' + hrs; } if(min<10){ min = '0' + min; } if(sec<10){ sec = '0' + sec; } document.getElementById('clock').innerHTML = hrs + ':'+ min + ':' + sec; } </script>

using random() function in javascript

//printing no. between 1-10 randomly var random = math.floor(math.random()*10) +1); console.log(random); 1) set hexcolor code with respect to the number(between 1-12). 2)  generate no. between 1-12. 3) use if else condition on numbers and render the colors with respect to the number generated by random function.

ds assignments stacks and queues

 Q1)  application of stacks: 1. Expression Evaluation  2. Expression Conversion i. Infix to Postfix ii. Infix to Prefix iii. Postfix to Infix iv. Prefix to Infix  3. Backtracking  application of queues : 1)  When a resource is shared among multiple consumers. Examples include CPU scheduling, Disk Scheduling. 2)  When data is transferred asynchronously (data not necessarily received at same rate as sent) between two processes. Examples include IO Buffers, pipes, file IO, etc. Q2)  Sparsh matrix: A sparse matrix is a  matrix in which many or most of the elements have a value of zero . This is in contrast to a dense matrix, where many or most of the elements have a non-zero value. a sparse matrix, substantial memory requirement reductions can be realized by storing only the non-zero entries. Depending on the number and distribution of the non-zero entries, different data structures can be used and yield huge savings in memory when compared to the basic approach. algorithm: 1. Initialize l

linked list stack

 #include <stdio.h> #include <stdlib.h> struct Node{     int data;     struct Node *next;      }; void linkedListTraversal(struct Node*ptr){     while(ptr!=NULL){         printf("Element: %d\n", ptr->data);         ptr = ptr->next;              } } int isEmpty(struct Node*top ){     if(top==NULL){         return 1;     }     else{         return 0;     } } int isFull(struct Node*top ){     struct Node*n=(struct Node*)malloc(sizeof(struct Node));     if(n==NULL){         return 1;     }     else{         return 0;     } } struct Node* push(struct Node*top, int x){     if(isFull(top)){         printf("Stack Overflow\n");              }     else{         struct Node*n=(struct Node*)malloc(sizeof(struct Node));         n->data= x;         n->next= top;         top = n;         return top;              } } int main() {     struct Node *top = NULL;     top = push(top, 78);      top = push(top, 79);      top = push(top, 80);      top = push(top, 81)