Sunday, November 9, 2014

C Programming for Beginners 7 - If Statements in C


















#include <stdio.h>
#include <stdlib.h>

int main()
{
int age;
printf("Please enter the age ");
scanf("%d",&age);
if (age > 18/* condition goes here */) {
/* if the condition is non-zero (true), this code will execute */
printf("The age is greater then 18");
}
if (age == 18/* condition goes here */) {
/* if the condition is non-zero (true), this code will execute */
printf("The age is equal to 18");
}
if (age < 18/* condition goes here */) {
/* if the condition is non-zero (true), this code will execute */
printf("The age is less then 18");
}
}





C Programming for Beginners 7 - If Statements in C





#include <stdio.h>
#include <stdlib.h>

int main()
{
int age;
printf("Please enter the age ");
scanf("%d",&age);
if (age > 18/* condition goes here */) {
/* if the condition is non-zero (true), this code will execute */
printf("The age is greater then 18");
}
if (age == 18/* condition goes here */) {
/* if the condition is non-zero (true), this code will execute */
printf("The age is equal to 18");
}
if (age < 18/* condition goes here */) {
/* if the condition is non-zero (true), this code will execute */
printf("The age is less then 18");
}
}





Tuesday, November 4, 2014

Module Chooser Using Javascript AND Apps Script

I had hoped that there might be a new Google Forms Add-on to do this, but no. I guess I'll have to have a go at doing it myself later.

Imagine you want your students to make a choice of four modules from a list of modules you're offering. To make the form easier to "not get wrong" it'd be good if when you chose module one, it disappeared from the following form items...

... like this.

The above is a hosted HTML on Google Drive ( because the Caja sanitation, or Chrome killed my Javascript ).

When a student chooses their preferred modules, the form is submitted to a regular doPost() method in a Google Spreadsheet's Apps Script like this...


function doPost(e) {
Logger.log("Hi there")
try{
//Get values from form
var email = Session.getActiveUser().getEmail()

var module_one = e.parameter.module_one
var module_two= e.parameter.module_two
var module_three = e.parameter.module_three
var module_four = e.parameter.module_four
add_students_selection(email,module_one,module_two,module_three,module_four )

var template = HtmlService.createTemplateFromFile('thank_you.html')
template.this_url = ScriptApp.getService().getUrl( )

return template.evaluate().setTitle("Thank You").setSandboxMode(HtmlService.SandboxMode.EMULATED)



}catch(e){
Logger.log(e)
var template = HtmlService.createTemplateFromFile('error.html');
template.this_url = ScriptApp.getService().getUrl( );
template.error_title = e
template.error_detail = e.stack
return template.evaluate().setTitle("Error").setSandboxMode(HtmlService.SandboxMode.EMULATED)
}

}

 

© 2013 Klick Dev. All rights resevered.

Back To Top