Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- // ----------------------------------------
- // Name: Shawon Roberts
- // ---------------------------------------
- // --------------------------------------
- // Exercise: Property Value Evaluation
- // --------------------------------------
- var obj = {
- a:1,
- b:{
- c: 2,
- d: 3
- }
- };
- function propertyValueAt(obj, key){
- for (key in obj) {
- if (obj.hasOwnProperty(key)) {
- console.log(key + " -> " + obj[key]);
- }
- }
- }
- propertyValueAt(obj, ['a']);
- // ----------------------------------------
- // Name: Shawon Roberts
- // ---------------------------------------
- // --------------------------------------
- // Exercise: fizzbuzz
- // --------------------------------------
- var n = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16];
- function fizzbuzz (n) {
- for(var i = 1; i < n.length; i++){
- if( i % 3 === 0 && i % 5 === 0){
- console.log(i + "fizzbuzz");
- }else if( i % 3 === 0){
- console.log(i + "fizz");
- }else if( i % 5 === 0){
- console.log(i + "buzz");
- }
- else{
- console.log(i);
- }
- }
- }
- console.log(fizzbuzz(n))
- // ----------------------------------------
- // Name: Shawon Roberts
- // ---------------------------------------
- // --------------------------------------
- // Exercise: Anagram tester
- // --------------------------------------
- function anagram(stringA, stringB){
- return cleanString(stringA) === cleanString(stringB);
- }
- function cleanString(str){
- return str.replace(/[^\w]/g, '').toLowerCase().split('').sort().join('');
- }
- console.log(anagram('abc', 'bca'));
- // ----------------------------------------
- // Name: Shawon Roberts
- // ---------------------------------------
- // --------------------------------------
- // Exercise: Sum nested
- // --------------------------------------
- function sumNested(i) {
- var sum=0;
- for(var a=0;a<i.length;a++){
- if(typeof i[a]=="number"){
- sum+=i[a];
- }else if(i[a] instanceof Array){
- sum+=arraySum(i[a]);
- }
- }
- return sum;
- }
- // ----------------------------------------
- // Name: Shawon Roberts
- // ---------------------------------------
- // --------------------------------------
- // Exercise: WordCount
- // --------------------------------------
- function wordCount(str) {
- var count = 0;
- for (var i = 1; i <= str.length; i++) {
- if (str.charAt(i) == " ") {
- count ++;
- }
- }
- return count + 1;
- }
- console.log(wordCount("This is the sentence I want to test my word count on"));
- // ------------------------------------------------------------------
- // Name: Shawon Roberts
- // ------------------------------------------------------------------
- // ------------------------------------------------------------------
- // Exercise: Object Oriented Programming - Car
- // ------------------------------------------------------------------
- // the following is in EC5
- function Car(speed){ // constructor function to create instances of Car
- this._speed = speed; //sets parameter speed to be the instance's speed
- getSpeed() { // returns the value of speed in the object instance
- return this._speed;
- };
- setSpeed(speed) { // sets speed in the object instance to be equal to the value passed in the method into if speed is greater than 0
- if (speed >=0){
- this._speed = speed;
- }
- };
- stop() { // sets the speed in the object instance to 0
- this._speed = 0;
- };
- }
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">// ----------------------------------------
- // Name: Shawon Roberts
- // ---------------------------------------
- // --------------------------------------
- // Exercise: Property Value Evaluation
- // --------------------------------------
- var obj = {
- a:1,
- b:{
- c: 2,
- d: 3
- }
- };
- function propertyValueAt(obj, key){
- for (key in obj) {
- if (obj.hasOwnProperty(key)) {
- console.log(key + " -> " + obj[key]);
- }
- }
- }
- propertyValueAt(obj, ['a']);
- // ----------------------------------------
- // Name: Shawon Roberts
- // ---------------------------------------
- // --------------------------------------
- // Exercise: fizzbuzz
- // --------------------------------------
- var n = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16];
- function fizzbuzz (n) {
- for(var i = 1; i < n.length; i++){
- if( i % 3 === 0 && i % 5 === 0){
- console.log(i + "fizzbuzz");
- }else if( i % 3 === 0){
- console.log(i + "fizz");
- }else if( i % 5 === 0){
- console.log(i + "buzz");
- }
- else{
- console.log(i);
- }
- }
- }
- console.log(fizzbuzz(n))
- // ----------------------------------------
- // Name: Shawon Roberts
- // ---------------------------------------
- // --------------------------------------
- // Exercise: Anagram tester
- // --------------------------------------
- function anagram(stringA, stringB){
- return cleanString(stringA) === cleanString(stringB);
- }
- function cleanString(str){
- return str.replace(/[^\w]/g, '').toLowerCase().split('').sort().join('');
- }
- console.log(anagram('abc', 'bca'));
- // ----------------------------------------
- // Name: Shawon Roberts
- // ---------------------------------------
- // --------------------------------------
- // Exercise: Sum nested
- // --------------------------------------
- function sumNested(i) {
- var sum=0;
- for(var a=0;a<i.length;a++){
- if(typeof i[a]=="number"){
- sum+=i[a];
- }else if(i[a] instanceof Array){
- sum+=arraySum(i[a]);
- }
- }
- return sum;
- }
- // ----------------------------------------
- // Name: Shawon Roberts
- // ---------------------------------------
- // --------------------------------------
- // Exercise: WordCount
- // --------------------------------------
- function wordCount(str) {
- var count = 0;
- for (var i = 1; i <= str.length; i++) {
- if (str.charAt(i) == " ") {
- count ++;
- }
- }
- return count + 1;
- }
- console.log(wordCount("This is the sentence I want to test my word count on"));
- // ------------------------------------------------------------------
- // Name: Shawon Roberts
- // ------------------------------------------------------------------
- // ------------------------------------------------------------------
- // Exercise: Object Oriented Programming - Car
- // ------------------------------------------------------------------
- // the following is in EC5
- function Car(speed){ // constructor function to create instances of Car
- this._speed = speed; //sets parameter speed to be the instance's speed
- getSpeed() { // returns the value of speed in the object instance
- return this._speed;
- };
- setSpeed(speed) { // sets speed in the object instance to be equal to the value passed in the method into if speed is greater than 0
- if (speed >=0){
- this._speed = speed;
- }
- };
- stop() { // sets the speed in the object instance to 0
- this._speed = 0;
- };
- }</script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement